File size: 1,897 Bytes
1e92f2d |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
package smoke
import (
"encoding/json"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/target/goalert/test/smoke/harness"
)
// TestAlertAutoClose verifies that inactive alerts are closed
// when `Maintenance.AlertAutoCloseDays` is set.
func TestAlertAutoClose(t *testing.T) {
t.Parallel()
sql := `
insert into escalation_policies (id, name)
values
({{uuid "eid"}}, 'esc policy');
insert into services (id, escalation_policy_id, name)
values
({{uuid "sid"}}, {{uuid "eid"}}, 'service');
insert into alerts (id, service_id, summary, status, dedup_key, created_at)
values
(1, {{uuid "sid"}}, 'testing1', 'triggered', 'test:1:foo', now() - '2 days'::interval),
(2, {{uuid "sid"}}, 'testing2', 'triggered', 'test:1:bar', now());
`
h := harness.NewHarness(t, sql, "site24x7-integration")
defer h.Close()
h.Trigger()
var data struct {
A *struct {
ID string
Status string
}
B *struct {
ID string
Status string
}
}
res := h.GraphQLQuery2("{a:alert(id: 1){id, status} b:alert(id: 2){id, status}}")
assert.Empty(t, res.Errors, "errors")
err := json.Unmarshal(res.Data, &data)
assert.NoError(t, err)
assert.Equal(t, "1", data.A.ID)
assert.Equal(t, "StatusUnacknowledged", data.A.Status)
assert.Equal(t, "2", data.B.ID)
assert.Equal(t, "StatusUnacknowledged", data.B.Status)
cfg := h.Config()
cfg.Maintenance.AlertAutoCloseDays = 1
h.RestartGoAlertWithConfig(cfg)
assert.EventuallyWithT(t, func(t *assert.CollectT) {
res = h.GraphQLQuery2("{a:alert(id: 1){id, status} b:alert(id: 2){id, status}}")
assert.Empty(t, res.Errors, "errors")
err = json.Unmarshal(res.Data, &data)
assert.NoError(t, err)
assert.Equal(t, "1", data.A.ID)
assert.Equal(t, "StatusClosed", data.A.Status)
assert.Equal(t, "2", data.B.ID)
assert.Equal(t, "StatusUnacknowledged", data.B.Status)
}, 15*time.Second, time.Second)
}
|