Skip to content

Commit 5d48ea2

Browse files
CLOUDP-64113: implementing e2e test for alerts ack and unack atlas (#186)
1 parent f9cf999 commit 5d48ea2

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

e2e/atlas/alerts_test.go

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import (
2121
"os/exec"
2222
"path/filepath"
2323
"testing"
24+
"time"
2425

2526
"github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
2627
)
2728

2829
const (
29-
closed = "CLOSED"
30-
replication_oplog_window_running_out = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
30+
open = "OPEN"
31+
users_without_multi_factor_auth = "USERS_WITHOUT_MULTI_FACTOR_AUTH"
3132
)
3233

3334
func TestAtlasAlerts(t *testing.T) {
@@ -43,9 +44,9 @@ func TestAtlasAlerts(t *testing.T) {
4344

4445
atlasEntity := "atlas"
4546
alertsEntity := "alerts"
47+
alertID := "5ecbef6b2359825e889837a7"
4648

4749
t.Run("Describe", func(t *testing.T) {
48-
alertID := "5e4d20ff5cc174527c22c606"
4950

5051
cmd := exec.Command(cliPath,
5152
atlasEntity,
@@ -72,12 +73,12 @@ func TestAtlasAlerts(t *testing.T) {
7273
t.Errorf("got=%#v\nwant=%#v\n", alert.ID, alertID)
7374
}
7475

75-
if alert.Status != closed {
76-
t.Errorf("got=%#v\nwant=%#v\n", alert.Status, closed)
76+
if alert.Status != open {
77+
t.Errorf("got=%#v\nwant=%#v\n", alert.Status, open)
7778
}
7879

79-
if alert.EventTypeName != replication_oplog_window_running_out {
80-
t.Errorf("got=%#v\nwant=%#v\n", alert.EventTypeName, replication_oplog_window_running_out)
80+
if alert.EventTypeName != users_without_multi_factor_auth {
81+
t.Errorf("got=%#v\nwant=%#v\n", alert.EventTypeName, users_without_multi_factor_auth)
8182
}
8283

8384
})
@@ -133,11 +134,12 @@ func TestAtlasAlerts(t *testing.T) {
133134
t.Fatalf("unexpected error: %v", err)
134135
}
135136

136-
if len(alerts.Results) > 0 {
137-
t.Errorf("got=%#v\nwant=0\n", len(alerts.Results))
137+
if len(alerts.Results) == 0 {
138+
t.Errorf("got=0\nwant>0\n")
138139
}
139140

140141
})
142+
141143
t.Run("List with status CLOSED", func(t *testing.T) {
142144

143145
cmd := exec.Command(cliPath,
@@ -167,4 +169,88 @@ func TestAtlasAlerts(t *testing.T) {
167169
}
168170

169171
})
172+
173+
t.Run("Acknowledge", func(t *testing.T) {
174+
175+
cmd := exec.Command(cliPath,
176+
atlasEntity,
177+
alertsEntity,
178+
"ack",
179+
alertID,
180+
"--until",
181+
time.Now().Format(time.RFC3339))
182+
183+
cmd.Env = os.Environ()
184+
resp, err := cmd.CombinedOutput()
185+
186+
if err != nil {
187+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
188+
}
189+
190+
alert := mongodbatlas.Alert{}
191+
err = json.Unmarshal(resp, &alert)
192+
193+
if err != nil {
194+
t.Fatalf("unexpected error: %v", err)
195+
}
196+
197+
if alert.ID != alertID {
198+
t.Errorf("got=%#v\nwant%v\n", alert.ID, alertID)
199+
}
200+
})
201+
202+
t.Run("Acknowledge Forever", func(t *testing.T) {
203+
204+
cmd := exec.Command(cliPath,
205+
atlasEntity,
206+
alertsEntity,
207+
"ack",
208+
alertID,
209+
"--forever")
210+
211+
cmd.Env = os.Environ()
212+
resp, err := cmd.CombinedOutput()
213+
214+
if err != nil {
215+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
216+
}
217+
218+
alert := mongodbatlas.Alert{}
219+
err = json.Unmarshal(resp, &alert)
220+
221+
if err != nil {
222+
t.Fatalf("unexpected error: %v", err)
223+
}
224+
225+
if alert.ID != alertID {
226+
t.Errorf("got=%#v\nwant%v\n", alert.ID, alertID)
227+
}
228+
})
229+
230+
t.Run("UnaAcknowledge", func(t *testing.T) {
231+
232+
cmd := exec.Command(cliPath,
233+
atlasEntity,
234+
alertsEntity,
235+
"unack",
236+
alertID)
237+
238+
cmd.Env = os.Environ()
239+
resp, err := cmd.CombinedOutput()
240+
241+
if err != nil {
242+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
243+
}
244+
245+
alert := mongodbatlas.Alert{}
246+
err = json.Unmarshal(resp, &alert)
247+
248+
if err != nil {
249+
t.Fatalf("unexpected error: %v", err)
250+
}
251+
252+
if alert.ID != alertID {
253+
t.Errorf("got=%#v\nwant%v\n", alert.ID, alertID)
254+
}
255+
})
170256
}

0 commit comments

Comments
 (0)