Skip to content

Commit

Permalink
Add acceptance tests for creating UTF-8 alerts
Browse files Browse the repository at this point in the history
Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Nov 15, 2023
1 parent c0dedde commit 9ec6b89
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/with_api_v2/acceptance/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,62 @@ import (
a "github.com/prometheus/alertmanager/test/with_api_v2"
)

func TestCreateUTF8Alerts(t *testing.T) {
t.Parallel()

conf := `
route:
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 10m
repeat_interval: 1h
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
`

at := a.NewAcceptanceTest(t, &a.AcceptanceOpts{
Tolerance: 1 * time.Second,
})
co := at.Collector("webhook")
wh := a.NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
require.NoError(t, amc.Start())
defer amc.Terminate()

am := amc.Members()[0]

now := time.Now()
expectedLabels := models.LabelSet{
"a": "a",
"00": "b",
"Σ": "c",
"\xf0\x9f\x99\x82": "dΘ",
}
pa := &models.PostableAlert{
StartsAt: strfmt.DateTime(now),
EndsAt: strfmt.DateTime(now.Add(5 * time.Minute)),
Alert: models.Alert{
Labels: expectedLabels,
},
}
alertParams := alert.NewPostAlertsParams()
alertParams.Alerts = models.PostableAlerts{pa}

_, err := am.Client().Alert.PostAlerts(alertParams)
require.NoError(t, err)

resp, err := am.Client().Alert.GetAlerts(nil)
require.NoError(t, err)
require.Len(t, resp.Payload, 1)

alert := resp.Payload[0]
require.Equal(t, expectedLabels, alert.Labels)
}

// TestAlertGetReturnsCurrentStatus checks that querying the API returns the
// current status of each alert, i.e. if it is silenced or inhibited.
func TestAlertGetReturnsCurrentAlertStatus(t *testing.T) {
Expand Down

0 comments on commit 9ec6b89

Please sign in to comment.