mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-12-02 16:09:25 +01:00
add strings functions test
Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
parent
1eb6c5e397
commit
acb31ccd03
@ -82,3 +82,33 @@ func TestAlertsDispatchedOnce(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringsFunctions(t *testing.T) {
|
||||
testingConfig := Config{
|
||||
MsgTemplate: "Alert {{ .GroupLabels.alertname | ToUpper }} is {{ .Status }}",
|
||||
MsgOnce: true,
|
||||
}
|
||||
formatter, _ := NewFormatter(&testingConfig)
|
||||
|
||||
expectedAlertMsgs := []AlertMsg{
|
||||
AlertMsg{
|
||||
Channel: "#somechannel",
|
||||
Alert: "Alert AIRDOWN is resolved",
|
||||
},
|
||||
}
|
||||
|
||||
var alertMessage = promtmpl.Data{}
|
||||
if err := json.Unmarshal([]byte(testdataSimpleAlertJson), &alertMessage); err != nil {
|
||||
t.Fatal(fmt.Sprintf("Could not unmarshal %s", testdataSimpleAlertJson))
|
||||
}
|
||||
|
||||
alertMsgs := formatter.GetMsgsFromAlertMessage("#somechannel", &alertMessage)
|
||||
|
||||
if !reflect.DeepEqual(expectedAlertMsgs, alertMsgs) {
|
||||
t.Error(fmt.Sprintf(
|
||||
"Unexpected alert msg.\nExpected: %s\nActual: %s",
|
||||
expectedAlertMsgs, alertMsgs))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user