The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
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.
 
 
 
 
 
 
grafana/pkg/services/ngalert/models/admin_configuration_test.go

61 lines
1016 B

package models
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestStringToAlertmanagersChoice(t *testing.T) {
tests := []struct {
name string
str string
alertmanagersChoice AlertmanagersChoice
err error
}{
{
"all alertmanagers",
"all",
AllAlertmanagers,
nil,
},
{
"internal alertmanager",
"internal",
InternalAlertmanager,
nil,
},
{
"external alertmanagers",
"external",
ExternalAlertmanagers,
nil,
},
{
"empty string value",
"",
AllAlertmanagers,
nil,
},
{
"invalid string",
"invalid",
0,
errors.New("invalid alertmanager choice"),
},
}
for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
amc, err := StringToAlertmanagersChoice(test.str)
if test.err != nil {
require.EqualError(tt, err, test.err.Error())
} else {
require.NoError(tt, err)
}
require.Equal(tt, amc, test.alertmanagersChoice)
})
}
}