@@ -21,13 +21,14 @@ import (
21
21
"os/exec"
22
22
"path/filepath"
23
23
"testing"
24
+ "time"
24
25
25
26
"github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
26
27
)
27
28
28
29
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 "
31
32
)
32
33
33
34
func TestAtlasAlerts (t * testing.T ) {
@@ -43,9 +44,9 @@ func TestAtlasAlerts(t *testing.T) {
43
44
44
45
atlasEntity := "atlas"
45
46
alertsEntity := "alerts"
47
+ alertID := "5ecbef6b2359825e889837a7"
46
48
47
49
t .Run ("Describe" , func (t * testing.T ) {
48
- alertID := "5e4d20ff5cc174527c22c606"
49
50
50
51
cmd := exec .Command (cliPath ,
51
52
atlasEntity ,
@@ -72,12 +73,12 @@ func TestAtlasAlerts(t *testing.T) {
72
73
t .Errorf ("got=%#v\n want=%#v\n " , alert .ID , alertID )
73
74
}
74
75
75
- if alert .Status != closed {
76
- t .Errorf ("got=%#v\n want=%#v\n " , alert .Status , closed )
76
+ if alert .Status != open {
77
+ t .Errorf ("got=%#v\n want=%#v\n " , alert .Status , open )
77
78
}
78
79
79
- if alert .EventTypeName != replication_oplog_window_running_out {
80
- t .Errorf ("got=%#v\n want=%#v\n " , alert .EventTypeName , replication_oplog_window_running_out )
80
+ if alert .EventTypeName != users_without_multi_factor_auth {
81
+ t .Errorf ("got=%#v\n want=%#v\n " , alert .EventTypeName , users_without_multi_factor_auth )
81
82
}
82
83
83
84
})
@@ -133,11 +134,12 @@ func TestAtlasAlerts(t *testing.T) {
133
134
t .Fatalf ("unexpected error: %v" , err )
134
135
}
135
136
136
- if len (alerts .Results ) > 0 {
137
- t .Errorf ("got=%#v \n want= 0\n " , len ( alerts . Results ) )
137
+ if len (alerts .Results ) == 0 {
138
+ t .Errorf ("got=0 \n want> 0\n " )
138
139
}
139
140
140
141
})
142
+
141
143
t .Run ("List with status CLOSED" , func (t * testing.T ) {
142
144
143
145
cmd := exec .Command (cliPath ,
@@ -167,4 +169,88 @@ func TestAtlasAlerts(t *testing.T) {
167
169
}
168
170
169
171
})
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\n want%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\n want%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\n want%v\n " , alert .ID , alertID )
254
+ }
255
+ })
170
256
}
0 commit comments