Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Oct 2, 2023
1 parent b7db815 commit ffb85e1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions libbeat/template/load_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/esleg/eslegclient"
"github.com/elastic/beats/v7/libbeat/esleg/eslegtest"
"github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle"
"github.com/elastic/beats/v7/libbeat/version"
"github.com/elastic/elastic-agent-libs/mapstr"
"github.com/elastic/elastic-agent-libs/transport/httpcommon"
Expand Down Expand Up @@ -68,7 +69,8 @@ func newTestSetup(t *testing.T, cfg TemplateConfig) *testSetup {
if err := client.Connect(); err != nil {
t.Fatal(err)
}
loader, err := NewESLoader(client)
handler := &mockClientHandler{severless: false, mode: lifecycle.ILM}
loader, err := NewESLoader(client, handler)
require.NoError(t, err)
s := testSetup{t: t, client: client, loader: loader, config: cfg}
// don't care if the cleanup fails, since they might just return a 404
Expand All @@ -84,7 +86,8 @@ func newTestSetupWithESClient(t *testing.T, client ESClient, cfg TemplateConfig)
if cfg.Name == "" {
cfg.Name = fmt.Sprintf("load-test-%+v", rand.Int())
}
loader, err := NewESLoader(client)
handler := &mockClientHandler{severless: false, mode: lifecycle.ILM}
loader, err := NewESLoader(client, handler)
require.NoError(t, err)
return &testSetup{t: t, client: client, loader: loader, config: cfg}
}
Expand Down Expand Up @@ -560,6 +563,22 @@ func getTestingElasticsearch(t eslegtest.TestLogger) *eslegclient.Connection {
return conn
}

type mockClientHandler struct {
severless bool
mode lifecycle.Mode
}

func (cli *mockClientHandler) IsServerless() bool { return cli.severless }
func (cli *mockClientHandler) CheckEnabled() (bool, error) { return true, nil }
func (cli *mockClientHandler) Mode() lifecycle.Mode { return cli.mode }
func (cli *mockClientHandler) IsElasticsearch() bool { return true }
func (cli *mockClientHandler) CheckExists() bool { return true }
func (cli *mockClientHandler) PolicyName() string { return "test" }
func (cli *mockClientHandler) HasPolicy() (bool, error) { return false, nil }
func (cli *mockClientHandler) CreatePolicyFromConfig() error { return nil }
func (cli *mockClientHandler) Policy() lifecycle.Policy { return lifecycle.Policy{Name: "test"} }
func (cli *mockClientHandler) Overwrite() bool { return true }

func getMockElasticsearchClient(t *testing.T, method, endpoint string, code int, body []byte) *eslegclient.Connection {
server := esMock(t, method, endpoint, code, body)
conn, err := eslegclient.NewConnection(eslegclient.ConnectionSettings{
Expand Down

0 comments on commit ffb85e1

Please sign in to comment.