2021-11-12 15:19:16 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
"errors"
|
2021-11-12 15:19:16 -06:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|