Skip to content

Commit cdbf97f

Browse files
committed
add action test
Signed-off-by: zzzk1 <[email protected]>
1 parent d65638b commit cdbf97f

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

cmd/es-rollover/app/init/action.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c Action) Do() error {
6060
if !policyExist {
6161
err := createDefaultILMPolicy(c.ILMClient, c.Config.ILMPolicyName)
6262
if err != nil {
63-
return fmt.Errorf("ILM policy %s Create/Update failed %w", c.Config.ILMPolicyName, err)
63+
return fmt.Errorf("ILM policy %s Create/Update failed", c.Config.ILMPolicyName)
6464
}
6565
}
6666
}

cmd/es-rollover/app/init/action_test.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,19 @@ func TestRolloverAction(t *testing.T) {
110110
},
111111
},
112112
{
113-
name: "ilm doesnt exist",
114-
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
113+
name: "create ILM policy",
114+
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
115115
clusterClient.On("Version").Return(uint(7), nil)
116116
ilmClient.On("Exists", "myilmpolicy").Return(false, nil)
117+
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
118+
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
119+
indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
120+
indexClient.On("CreateAlias", []client.Alias{
121+
{Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-read", IsWriteIndex: false},
122+
{Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-write", IsWriteIndex: true},
123+
}).Return(nil)
124+
ilmClient.On("CreateOrUpdate", "myilmpolicy", mock.Anything).Return(nil)
117125
},
118-
expectedErr: errors.New("ILM policy myilmpolicy doesn't exist in Elasticsearch. Please create it and re-run init"),
119126
config: Config{
120127
Config: app.Config{
121128
Archive: true,

plugin/storage/integration/elasticsearch_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,16 @@ func TestElasticsearchStorage_ILMPolicy(t *testing.T) {
263263
ilmPolicyExistsResponse, err := s.v8Client.ILM.GetLifecycle(request)
264264
require.NoError(t, err)
265265
assert.Equal(t, 200, ilmPolicyExistsResponse.StatusCode)
266-
} else {
267-
// nothing
268266
}
269-
s.cleanEsILMPolicy(t, ilmPolicy)
267+
s.cleanEsILMPolicy(t)
270268
}
271269

272-
func (s *ESStorageIntegration) cleanEsILMPolicy(t *testing.T, policy string) error {
270+
func (s *ESStorageIntegration) cleanEsILMPolicy(t *testing.T) error {
273271
version, err := s.getVersion()
274272
require.NoError(t, err)
275273
if version == 8 {
276274
_, err := s.v8Client.ILM.RemovePolicy(ilmPolicy)
277275
require.NoError(t, err)
278-
} else {
279-
// nothing
280276
}
281277
return nil
282278
}

0 commit comments

Comments
 (0)