forked from grafana/cortex-tools
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrules_test.go
More file actions
63 lines (59 loc) · 1.2 KB
/
rules_test.go
File metadata and controls
63 lines (59 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package commands
import (
"testing"
"github.com/prometheus/prometheus/model/rulefmt"
"github.com/stretchr/testify/assert"
"github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt"
)
func TestCheckDuplicates(t *testing.T) {
for _, tc := range []struct {
name string
in []rwrulefmt.RuleGroup
want []compareRuleType
}{
{
name: "no duplicates",
in: []rwrulefmt.RuleGroup{{
RuleGroup: rulefmt.RuleGroup{
Name: "rulegroup",
Rules: []rulefmt.Rule{
{
Record: "up",
Expr: "up==1",
},
{
Record: "down",
Expr: "up==0",
},
},
},
RWConfigs: []rwrulefmt.RemoteWriteConfig{},
}},
want: nil,
},
{
name: "with duplicates",
in: []rwrulefmt.RuleGroup{{
RuleGroup: rulefmt.RuleGroup{
Name: "rulegroup",
Rules: []rulefmt.Rule{
{
Record: "up",
Expr: "up==1",
},
{
Record: "up",
Expr: "up==0",
},
},
},
RWConfigs: []rwrulefmt.RemoteWriteConfig{},
}},
want: []compareRuleType{{metric: "up", label: map[string]string(nil)}},
},
} {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, checkDuplicates(tc.in))
})
}
}