-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmackerel_test.go
120 lines (114 loc) · 3.29 KB
/
mackerel_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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package shimesaba_test
import (
"context"
"testing"
"time"
"github.com/mashiike/shimesaba"
"github.com/stretchr/testify/require"
)
func TestRepositoryFetchVirtualAlerts(t *testing.T) {
client := newMockMackerelClient(t)
repo := shimesaba.NewRepository(client)
cases := []struct {
name string
serviceName string
sloID string
startAt time.Time
endAt time.Time
expected shimesaba.Alerts
}{
{
name: "SLO:*",
serviceName: "shimesaba",
sloID: "hoge",
startAt: time.Date(2021, 10, 1, 0, 5, 0, 0, time.UTC),
endAt: time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC),
expected: shimesaba.Alerts{
{
Reason: "SLO:*",
OpenedAt: time.Date(2021, 10, 1, 0, 10, 0, 0, time.UTC),
ClosedAt: ptrTime(time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC)),
},
},
},
{
name: "SLO:availability,quarity ",
serviceName: "shimesaba",
sloID: "availability",
startAt: time.Date(2021, 10, 1, 0, 5, 0, 0, time.UTC),
endAt: time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC),
expected: shimesaba.Alerts{
{
Reason: "SLO:*",
OpenedAt: time.Date(2021, 10, 1, 0, 10, 0, 0, time.UTC),
ClosedAt: ptrTime(time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC)),
},
{
Reason: "ALB Failures SLO:availability,quarity affected.",
OpenedAt: time.Date(2021, 10, 1, 0, 10, 0, 0, time.UTC),
ClosedAt: ptrTime(time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC)),
},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
vAlerts, err := repo.FetchVirtualAlerts(context.Background(), c.serviceName, c.sloID, c.startAt, c.endAt)
require.NoError(t, err)
require.EqualValues(t, c.expected, vAlerts)
})
}
}
func TestRepositoryFetchAlerts(t *testing.T) {
client := newMockMackerelClient(t)
repo := shimesaba.NewRepository(client)
cases := []struct {
name string
startAt time.Time
endAt time.Time
expected shimesaba.Alerts
}{
{
name: "Alerts service",
startAt: time.Date(2021, 10, 1, 0, 5, 0, 0, time.UTC),
endAt: time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC),
expected: shimesaba.Alerts{
{
OpenedAt: time.Date(2021, 10, 1, 0, 10, 0, 0, time.UTC),
Monitor: shimesaba.NewMonitor("dummyMonitorID", "Dummy Service Metric Monitor", "service"),
ClosedAt: ptrTime(time.Date(2021, 10, 1, 0, 15, 0, 0, time.UTC)),
},
},
},
{
name: "No alerts",
startAt: time.Date(2022, 10, 1, 0, 5, 0, 0, time.UTC),
endAt: time.Date(2022, 10, 1, 0, 15, 0, 0, time.UTC),
expected: shimesaba.Alerts{},
},
{
name: "check monitor",
startAt: time.Date(2021, 10, 1, 0, 17, 0, 0, time.UTC),
endAt: time.Date(2021, 10, 1, 0, 18, 0, 0, time.UTC),
expected: shimesaba.Alerts{
{
OpenedAt: time.Date(2021, 10, 1, 0, 17, 0, 0, time.UTC),
Monitor: shimesaba.NewMonitor("dummyCheckMonitorID", "check monitor dummyCheckMonitorID", "check"),
ClosedAt: nil,
},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
alerts, err := repo.FetchAlerts(context.Background(), c.startAt, c.endAt)
require.NoError(t, err)
for _, a := range alerts {
if a.Monitor != nil {
a.Monitor = a.Monitor.WithEvaluator(nil)
}
}
require.EqualValues(t, c.expected, alerts)
})
}
}