diff --git a/e2e/atlas/dbusers_test.go b/e2e/atlas/dbusers_test.go index ef9a55315a..92455a00f7 100644 --- a/e2e/atlas/dbusers_test.go +++ b/e2e/atlas/dbusers_test.go @@ -83,6 +83,13 @@ func TestAtlasDBUsers(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) } + + users := []mongodbatlas.DatabaseUser{} + err = json.Unmarshal(resp, &users) + + if len(users) == 0 { + t.Fatalf("expected len(users) > 0, got 0") + } }) t.Run("Update", func(t *testing.T) { diff --git a/e2e/cloud_manager/dbusers_test.go b/e2e/cloud_manager/dbusers_test.go new file mode 100644 index 0000000000..80c84704ef --- /dev/null +++ b/e2e/cloud_manager/dbusers_test.go @@ -0,0 +1,106 @@ +// Copyright 2020 MongoDB Inc +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +build e2e + +package cloud_manager_test + +import ( + "encoding/json" + "fmt" + "math/rand" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" +) + +const ( + roleReadWrite = "readWrite" +) + +func TestCloudManagerDBUsers(t *testing.T) { + cliPath, err := filepath.Abs("../../bin/mongocli") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + _, err = os.Stat(cliPath) + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + r := rand.New(rand.NewSource(time.Now().UnixNano())) + + entity := "cloud-manager" + dbusersEntity := "dbusers" + username := fmt.Sprintf("user-%v", r.Uint32()) + + t.Run("Create", func(t *testing.T) { + cmd := exec.Command(cliPath, + entity, + dbusersEntity, + "create", + "--username="+username, + "--password=passW0rd", + "--role=readWriteAnyDatabase", + "--mechanisms=SCRAM-SHA-256 ") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + + if !strings.Contains(string(resp), "Changes are being applied") { + t.Errorf("got=%#v\nwant=%#v\n", string(resp), "Changes are being applied") + } + }) + + t.Run("List", func(t *testing.T) { + cmd := exec.Command(cliPath, entity, dbusersEntity, "ls") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + + users := []mongodbatlas.DatabaseUser{} + err = json.Unmarshal(resp, &users) + + if len(users) == 0 { + t.Fatalf("expected len(users) > 0, got 0") + } + + }) + + t.Run("Delete", func(t *testing.T) { + cmd := exec.Command(cliPath, entity, dbusersEntity, "delete", username, "--force", "--authDB", "admin") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + + if !strings.Contains(string(resp), "Changes are being applied") { + t.Errorf("got=%#v\nwant=%#v\n", string(resp), "Changes are being applied") + } + }) + +} diff --git a/internal/cli/ops_manager_dbusers_create.go b/internal/cli/ops_manager_dbusers_create.go index 592b153cea..4546243318 100644 --- a/internal/cli/ops_manager_dbusers_create.go +++ b/internal/cli/ops_manager_dbusers_create.go @@ -92,7 +92,7 @@ func OpsManagerDBUsersCreateBuilder() *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: description.CreateDBUser, - Example: ` mongocli om dbuser create --username User1 --password passW0rd --role readWriteAnyDatabase,clusterMonitor --mechanisms SCRAM-SHA-256 --projectId <>`, + Example: `mongocli om dbuser create --username User1 --password passW0rd --role readWriteAnyDatabase,clusterMonitor --mechanisms SCRAM-SHA-256 --projectId <>`, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { if err := opts.PreRunE(opts.initStore); err != nil {