mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
babfa2beac
This PR connects the new RBAC authentication service to existing alertmanager API silence endpoints.
51 lines
1.5 KiB
Go
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")
|
|
})
|
|
}
|
|
}
|