grafana/pkg/services/ngalert/models/silence_test.go
Matthew Jacobson babfa2beac
Alerting: Hook up GMA silence APIs to new authentication handler (#86625)
This PR connects the new RBAC authentication service to existing alertmanager API silence endpoints.
2024-05-03 15:32:30 -04:00

51 lines
1.5 KiB
Go

package models
import (
"testing"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/stretchr/testify/assert"
"github.com/grafana/alerting/models"
"github.com/grafana/grafana/pkg/util"
)
func TestSilenceGetRuleUID(t *testing.T) {
testCases := []struct {
name string
silence Silence
expectedRuleUID *string
}{
{
name: "silence with no rule UID",
silence: SilenceGen()(),
expectedRuleUID: nil,
},
{
name: "silence with rule UID",
silence: SilenceGen(SilenceMuts.WithMatcher(models.RuleUIDLabel, "someuid", labels.MatchEqual))(),
expectedRuleUID: util.Pointer("someuid"),
},
{
name: "silence with rule UID Matcher but MatchNotEqual",
silence: SilenceGen(SilenceMuts.WithMatcher(models.RuleUIDLabel, "someuid", labels.MatchNotEqual))(),
expectedRuleUID: nil,
},
{
name: "silence with rule UID Matcher but MatchRegexp",
silence: SilenceGen(SilenceMuts.WithMatcher(models.RuleUIDLabel, "someuid", labels.MatchRegexp))(),
expectedRuleUID: nil,
},
{
name: "silence with rule UID Matcher but MatchNotRegexp",
silence: SilenceGen(SilenceMuts.WithMatcher(models.RuleUIDLabel, "someuid", labels.MatchNotRegexp))(),
expectedRuleUID: nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expectedRuleUID, tt.silence.GetRuleUID(), "unexpected rule UID")
})
}
}