Add unit test case for func HasAlertingRules in manager.go (#7502)

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
This commit is contained in:
Guangwen Feng 2020-07-06 17:35:16 +08:00 committed by GitHub
parent f32307b656
commit ad9449d1f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -1118,3 +1118,42 @@ func countStaleNaN(t *testing.T, st storage.Storage) int {
}
return c
}
func TestGroupHasAlertingRules(t *testing.T) {
tests := []struct {
group *Group
want bool
}{
{
group: &Group{
name: "HasAlertingRule",
rules: []Rule{
NewAlertingRule("alert", nil, 0, nil, nil, nil, true, nil),
NewRecordingRule("record", nil, nil),
},
},
want: true,
},
{
group: &Group{
name: "HasNoRule",
rules: []Rule{},
},
want: false,
},
{
group: &Group{
name: "HasOnlyRecordingRule",
rules: []Rule{
NewRecordingRule("record", nil, nil),
},
},
want: false,
},
}
for i, test := range tests {
got := test.group.HasAlertingRules()
testutil.Assert(t, test.want == got, "test case %d failed, expected:%t got:%t", i, test.want, got)
}
}