mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
45facbba11
* Remove URL-based alertmanagers from endpoint config * WIP * Add migration and alertmanagers from admin_configuration * Empty comment removed * set BasicAuth true when user is present in url * Remove Alertmanagers from GET /admin_config payload * Remove URL-based alertmanager configuration from UI * Fix new uid generation in external alertmanagers migration * Fix tests for URL-based external alertmanagers * Fix API tests * Add more tests, move migration code to separate file, and remove possible am duplicate urls * Fix edge cases in migration * Fix imports * Remove useless fields and fix created_at/updated_at retrieval Co-authored-by: George Robinson <george.robinson@grafana.com> Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
62 lines
1016 B
Go
62 lines
1016 B
Go
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)
|
|
})
|
|
}
|
|
}
|