-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalerts_test.go
35 lines (31 loc) · 856 Bytes
/
alerts_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestAlertFiring(t *testing.T) {
var a *AlertFire
a = new(AlertFire)
a.Status = "firing"
a.Labels.Alertname = "testing-alert"
a.Labels.Component = "unit-test component"
a.Labels.Severity = "critical"
a.Labels.Instance = "test instance"
a.Annotations.Summary = "just a test"
a.GeneratorURL = "unit-test"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// read body json from Prometheus alertmanager
decoder := json.NewDecoder(r.Body)
alert := make([]AlertFire, 1)
decoder.Decode(&alert)
t.Log(alert[0].Status)
t.Log(alert[0].Labels.Component)
if alert[0].GeneratorURL != "unit-test" {
t.Errorf("got %s expected unit-test", alert[0].GeneratorURL)
}
}))
defer ts.Close()
a.sendAlert(ts.URL)
}