Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
  • Loading branch information
jkandasa committed Nov 10, 2021
1 parent 8b96295 commit 1c5dfee
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions pkg/es/client/index_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,38 +166,45 @@ func TestClientDeleteIndices(t *testing.T) {
triggerAPI bool
}{
{
name: "no error",
name: "no indices",
responseCode: http.StatusOK,
indices: []Index{},
triggerAPI: false,
}, {
name: "one index",
responseCode: http.StatusOK,
indices: []Index{{Index: "jaeger-span-000001"}},
triggerAPI: true,
},
{
name: "client error",
responseCode: http.StatusBadRequest,
response: esErrResponse,
errContains: "failed to delete indices: jaeger-span-000001",
indices: []Index{{Index: "jaeger-span-000001"}},
name: "moderate indices",
responseCode: http.StatusOK,
response: "",
indices: getIndicesList(20),
triggerAPI: true,
},
{
name: "long indices list",
name: "long indices",
responseCode: http.StatusOK,
response: "",
indices: getIndicesList(600),
triggerAPI: true,
},
{
name: "moderate indices list",
responseCode: http.StatusOK,
response: "",
indices: getIndicesList(20),
name: "client error",
responseCode: http.StatusBadRequest,
response: esErrResponse,
errContains: "failed to delete indices: jaeger-span-000001",
indices: []Index{{Index: "jaeger-span-000001"}},
triggerAPI: true,
},
{
name: "no indices",
responseCode: http.StatusOK,
indices: []Index{},
triggerAPI: false,
name: "client error in long indices",
responseCode: http.StatusBadRequest,
response: esErrResponse,
errContains: "failed to delete indices: jaeger-span-000001",
indices: getIndicesList(600),
triggerAPI: true,
},
}
for _, test := range tests {
Expand Down Expand Up @@ -239,12 +246,13 @@ func TestClientDeleteIndices(t *testing.T) {
}

err := c.DeleteIndices(test.indices)
assert.Equal(t, len(test.indices), deletedIndicesCount)
assert.Equal(t, test.triggerAPI, apiTriggered)

if test.errContains != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), test.errContains)
} else {
assert.Equal(t, len(test.indices), deletedIndicesCount)
}
})
}
Expand Down

0 comments on commit 1c5dfee

Please sign in to comment.