Skip to content

Commit b547a41

Browse files
CLOUDP-62813: add alerts e2e test - cloud manager (#176)
1 parent b4690b0 commit b547a41

File tree

8 files changed

+171
-0
lines changed

8 files changed

+171
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ e2e-test-atlas: build ## Run Atlas E2E tests
101101
e2e-test-cloud: build ## Run IAM E2E tests
102102
@echo "==> Running Cloud Manger E2E tests..."
103103
# the target assumes the MCLI-* environment variables are exported
104+
go test -v -p 1 -parallel 1 -tags=e2e ./e2e/cloud_manager...
104105
go test -v -p 1 -parallel 1 -tags=e2e ./e2e/iam...
105106

106107
.PHONY: e2e-test
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

e2e/cloud_manager/alerts_test.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// +build e2e
15+
16+
package cloud_manager_test
17+
18+
import (
19+
"encoding/json"
20+
"os"
21+
"os/exec"
22+
"path/filepath"
23+
"testing"
24+
25+
"github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
26+
)
27+
28+
const (
29+
open = "OPEN"
30+
users_without_multi_factor_auth = "USERS_WITHOUT_MULTI_FACTOR_AUTH"
31+
)
32+
33+
func TestCloudManagerAlerts(t *testing.T) {
34+
cliPath, err := filepath.Abs("../../bin/mongocli")
35+
if err != nil {
36+
t.Fatalf("unexpected error: %v", err)
37+
}
38+
_, err = os.Stat(cliPath)
39+
40+
if err != nil {
41+
t.Fatalf("unexpected error: %v", err)
42+
}
43+
44+
entity := "cloud-manager"
45+
alertsEntity := "alerts"
46+
47+
t.Run("Describe", func(t *testing.T) {
48+
alertID := "5ec2ac941271767f21cbaefe"
49+
50+
cmd := exec.Command(cliPath,
51+
entity,
52+
alertsEntity,
53+
"describe",
54+
alertID,
55+
)
56+
57+
cmd.Env = os.Environ()
58+
resp, err := cmd.CombinedOutput()
59+
60+
if err != nil {
61+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
62+
}
63+
64+
alert := mongodbatlas.Alert{}
65+
err = json.Unmarshal(resp, &alert)
66+
67+
if err != nil {
68+
t.Fatalf("unexpected error: %v", err)
69+
}
70+
71+
if alert.ID != alertID {
72+
t.Errorf("got=%#v\nwant=%#v\n", alert.ID, alertID)
73+
}
74+
75+
if alert.Status != open {
76+
t.Errorf("got=%#v\nwant=%#v\n", alert.Status, open)
77+
}
78+
79+
if alert.EventTypeName != users_without_multi_factor_auth {
80+
t.Errorf("got=%#v\nwant=%#v\n", alert.EventTypeName, users_without_multi_factor_auth)
81+
}
82+
83+
})
84+
85+
t.Run("List with no status", func(t *testing.T) {
86+
87+
cmd := exec.Command(cliPath,
88+
entity,
89+
alertsEntity,
90+
"list",
91+
)
92+
93+
cmd.Env = os.Environ()
94+
resp, err := cmd.CombinedOutput()
95+
96+
if err != nil {
97+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
98+
}
99+
100+
alerts := mongodbatlas.AlertsResponse{}
101+
err = json.Unmarshal(resp, &alerts)
102+
103+
if err != nil {
104+
t.Fatalf("unexpected error: %v", err)
105+
}
106+
107+
if len(alerts.Results) == 0 {
108+
t.Errorf("got=%#v\nwant>0\n", len(alerts.Results))
109+
}
110+
111+
})
112+
t.Run("List with status OPEN", func(t *testing.T) {
113+
114+
cmd := exec.Command(cliPath,
115+
entity,
116+
alertsEntity,
117+
"list",
118+
"--status",
119+
"OPEN",
120+
)
121+
122+
cmd.Env = os.Environ()
123+
resp, err := cmd.CombinedOutput()
124+
125+
if err != nil {
126+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
127+
}
128+
129+
alerts := mongodbatlas.AlertsResponse{}
130+
err = json.Unmarshal(resp, &alerts)
131+
132+
if err != nil {
133+
t.Fatalf("unexpected error: %v", err)
134+
}
135+
136+
if len(alerts.Results) == 0 {
137+
t.Errorf("got=%#v\nwant=0\n", len(alerts.Results))
138+
}
139+
140+
})
141+
t.Run("List with status CLOSED", func(t *testing.T) {
142+
143+
cmd := exec.Command(cliPath,
144+
entity,
145+
alertsEntity,
146+
"list",
147+
"--status",
148+
"CLOSED",
149+
)
150+
151+
cmd.Env = os.Environ()
152+
resp, err := cmd.CombinedOutput()
153+
154+
if err != nil {
155+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
156+
}
157+
158+
alerts := mongodbatlas.AlertsResponse{}
159+
err = json.Unmarshal(resp, &alerts)
160+
161+
if err != nil {
162+
t.Fatalf("unexpected error: %v", err)
163+
}
164+
165+
if len(alerts.Results) > 0 {
166+
t.Errorf("got=%#v\nwant>0\n", len(alerts.Results))
167+
}
168+
169+
})
170+
}

0 commit comments

Comments
 (0)