Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/tool/commands/rules_test.go

63 lines
1.2 KiB

package commands
import (
"testing"
"github.com/prometheus/prometheus/model/rulefmt"
"github.com/stretchr/testify/assert"
"github.com/grafana/loki/v3/pkg/tool/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))
})
}
}