Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions libbeat/tests/integration/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bufio"
"bytes"
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand All @@ -42,6 +43,8 @@ import (
"testing"
"time"

"github.com/elastic/go-elasticsearch/v8"

"github.com/gofrs/uuid/v5"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -717,6 +720,32 @@ func EnsureESIsRunning(t *testing.T) {
}
}

func GetESClient(t *testing.T, scheme string) *elasticsearch.Client {
t.Helper()
esURL := GetESURL(t, scheme)

u := esURL.User.Username()
p, _ := esURL.User.Password()

// prepare to query ES
esCfg := elasticsearch.Config{
Addresses: []string{fmt.Sprintf("%s://%s", esURL.Scheme, esURL.Host)},
Username: u,
Password: p,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, //nolint:gosec // this is only for testing
},
},
}
es, err := elasticsearch.NewClient(esCfg)
if err != nil {
t.Fatalf("could not get elasticsearch client due to: %v", err)
}
return es

}

func (b *BeatProc) FileContains(filename string, match string) string {
file, err := os.Open(filename)
require.NoErrorf(b.t, err, "error opening: %s", filename)
Expand Down
Loading