Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Oct 14, 2024
1 parent 5875622 commit 4448390
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion extkafka/check_topic_lag_for_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ func TestCheckConsumerGroupLag_Status(t *testing.T) {
Topic: "steadybit",
},
},
{
name: "Should return status ko",
requestBody: extutil.JsonMangle(action_kit_api.PrepareActionRequestBody{
Target: &action_kit_api.Target{
Attributes: map[string][]string{
"kafka.consumer-group.name": {"steadybit"},
},
},
Config: map[string]interface{}{
"duration": 5000,
"topic": "steadybit",
"acceptableLag": "1",
},
ExecutionId: uuid.New(),
}),

wantedState: &ConsumerGroupLagCheckState{
ConsumerGroupName: "steadybit",
AcceptableLag: int64(1),
StateCheckSuccess: true,
Topic: "steadybit",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -209,7 +232,13 @@ func TestCheckConsumerGroupLag_Status(t *testing.T) {
assert.Equal(t, tt.wantedState.AcceptableLag, state.AcceptableLag)
assert.Equal(t, tt.wantedState.Topic, state.Topic)
assert.Equal(t, tt.wantedState.ConsumerGroupName, state.ConsumerGroupName)
assert.Equal(t, true, statusResult.Completed)
for _, metric := range *statusResult.Metrics {
if tt.wantedState.AcceptableLag > 10 {
assert.Equal(t, "success", metric.Metric["state"], "Expected metric state to be 'danger'")
} else {
assert.Equal(t, "danger", metric.Metric["state"], "Expected metric state to be 'danger'")
}
}
assert.NotNil(t, state.End)
}
})
Expand Down

0 comments on commit 4448390

Please sign in to comment.