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

64 lines
1.4 KiB

package commands
import (
"testing"
"github.com/prometheus/prometheus/model/rulefmt"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"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.RuleNode{
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "up==1"},
},
{
Record: yaml.Node{Value: "down"},
Expr: yaml.Node{Value: "up==0"},
},
},
},
RWConfigs: []rwrulefmt.RemoteWriteConfig{},
}},
want: nil,
},
{
name: "with duplicates",
in: []rwrulefmt.RuleGroup{{
RuleGroup: rulefmt.RuleGroup{
Name: "rulegroup",
Rules: []rulefmt.RuleNode{
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "up==1"},
},
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "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))
})
}
}