Skip to content

Commit 724e61f

Browse files
CLOUDP-62814: add DBUsers e2e test - cloud manager (#177)
1 parent 81955bf commit 724e61f

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

e2e/atlas/dbusers_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ func TestAtlasDBUsers(t *testing.T) {
8383
if err != nil {
8484
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
8585
}
86+
87+
users := []mongodbatlas.DatabaseUser{}
88+
err = json.Unmarshal(resp, &users)
89+
90+
if len(users) == 0 {
91+
t.Fatalf("expected len(users) > 0, got 0")
92+
}
8693
})
8794

8895
t.Run("Update", func(t *testing.T) {

e2e/cloud_manager/dbusers_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
"fmt"
21+
"math/rand"
22+
"os"
23+
"os/exec"
24+
"path/filepath"
25+
"strings"
26+
"testing"
27+
"time"
28+
29+
"github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
30+
)
31+
32+
const (
33+
roleReadWrite = "readWrite"
34+
)
35+
36+
func TestCloudManagerDBUsers(t *testing.T) {
37+
cliPath, err := filepath.Abs("../../bin/mongocli")
38+
if err != nil {
39+
t.Fatalf("unexpected error: %v", err)
40+
}
41+
_, err = os.Stat(cliPath)
42+
43+
if err != nil {
44+
t.Fatalf("unexpected error: %v", err)
45+
}
46+
47+
r := rand.New(rand.NewSource(time.Now().UnixNano()))
48+
49+
entity := "cloud-manager"
50+
dbusersEntity := "dbusers"
51+
username := fmt.Sprintf("user-%v", r.Uint32())
52+
53+
t.Run("Create", func(t *testing.T) {
54+
cmd := exec.Command(cliPath,
55+
entity,
56+
dbusersEntity,
57+
"create",
58+
"--username="+username,
59+
"--password=passW0rd",
60+
"--role=readWriteAnyDatabase",
61+
"--mechanisms=SCRAM-SHA-256 ")
62+
cmd.Env = os.Environ()
63+
resp, err := cmd.CombinedOutput()
64+
65+
if err != nil {
66+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
67+
}
68+
69+
if !strings.Contains(string(resp), "Changes are being applied") {
70+
t.Errorf("got=%#v\nwant=%#v\n", string(resp), "Changes are being applied")
71+
}
72+
})
73+
74+
t.Run("List", func(t *testing.T) {
75+
cmd := exec.Command(cliPath, entity, dbusersEntity, "ls")
76+
cmd.Env = os.Environ()
77+
resp, err := cmd.CombinedOutput()
78+
79+
if err != nil {
80+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
81+
}
82+
83+
users := []mongodbatlas.DatabaseUser{}
84+
err = json.Unmarshal(resp, &users)
85+
86+
if len(users) == 0 {
87+
t.Fatalf("expected len(users) > 0, got 0")
88+
}
89+
90+
})
91+
92+
t.Run("Delete", func(t *testing.T) {
93+
cmd := exec.Command(cliPath, entity, dbusersEntity, "delete", username, "--force", "--authDB", "admin")
94+
cmd.Env = os.Environ()
95+
resp, err := cmd.CombinedOutput()
96+
97+
if err != nil {
98+
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
99+
}
100+
101+
if !strings.Contains(string(resp), "Changes are being applied") {
102+
t.Errorf("got=%#v\nwant=%#v\n", string(resp), "Changes are being applied")
103+
}
104+
})
105+
106+
}

internal/cli/ops_manager_dbusers_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func OpsManagerDBUsersCreateBuilder() *cobra.Command {
9292
cmd := &cobra.Command{
9393
Use: "create",
9494
Short: description.CreateDBUser,
95-
Example: ` mongocli om dbuser create --username User1 --password passW0rd --role readWriteAnyDatabase,clusterMonitor --mechanisms SCRAM-SHA-256 --projectId <>`,
95+
Example: `mongocli om dbuser create --username User1 --password passW0rd --role readWriteAnyDatabase,clusterMonitor --mechanisms SCRAM-SHA-256 --projectId <>`,
9696
Args: cobra.NoArgs,
9797
PreRunE: func(cmd *cobra.Command, args []string) error {
9898
if err := opts.PreRunE(opts.initStore); err != nil {

0 commit comments

Comments
 (0)