From 7280ffb62286010b801f698f6669ee7d6788d7b5 Mon Sep 17 00:00:00 2001 From: Gustavo Bazan Date: Mon, 11 Mar 2024 17:27:26 +0000 Subject: [PATCH] task: delete atlas iam tests (#2751) --- test/e2e/cli.go | 13 -- .../iam/atlas_org_api_key_access_list_test.go | 127 ------------ test/e2e/iam/atlas_org_api_keys_test.go | 137 ------------- test/e2e/iam/atlas_org_invitations_test.go | 154 --------------- test/e2e/iam/atlas_orgs_test.go | 134 ------------- test/e2e/iam/atlas_project_api_keys_test.go | 133 ------------- .../e2e/iam/atlas_project_invitations_test.go | 181 ------------------ test/e2e/iam/atlas_project_teams_test.go | 144 -------------- test/e2e/iam/atlas_projects_test.go | 145 -------------- test/e2e/iam/atlas_team_users_test.go | 131 ------------- test/e2e/iam/atlas_teams_test.go | 163 ---------------- test/e2e/iam/atlas_users_test.go | 123 ------------ test/e2e/iam/orgs_test.go | 6 +- 13 files changed, 3 insertions(+), 1588 deletions(-) delete mode 100644 test/e2e/iam/atlas_org_api_key_access_list_test.go delete mode 100644 test/e2e/iam/atlas_org_api_keys_test.go delete mode 100644 test/e2e/iam/atlas_org_invitations_test.go delete mode 100644 test/e2e/iam/atlas_orgs_test.go delete mode 100644 test/e2e/iam/atlas_project_api_keys_test.go delete mode 100644 test/e2e/iam/atlas_project_invitations_test.go delete mode 100644 test/e2e/iam/atlas_project_teams_test.go delete mode 100644 test/e2e/iam/atlas_projects_test.go delete mode 100644 test/e2e/iam/atlas_team_users_test.go delete mode 100644 test/e2e/iam/atlas_teams_test.go delete mode 100644 test/e2e/iam/atlas_users_test.go diff --git a/test/e2e/cli.go b/test/e2e/cli.go index cfbf5ed01a..d1d10622c0 100644 --- a/test/e2e/cli.go +++ b/test/e2e/cli.go @@ -35,19 +35,6 @@ func Bin() (string, error) { return cliPath, nil } -func AtlasCLIBin() (string, error) { - path := os.Getenv("ATLAS_E2E_BINARY") - cliPath, err := filepath.Abs(path) - if err != nil { - return "", fmt.Errorf("%w: invalid bin path %q", err, path) - } - - if _, err := os.Stat(cliPath); err != nil { - return "", fmt.Errorf("%w: invalid bin %q", err, path) - } - return cliPath, nil -} - func RandInt(max int64) (*big.Int, error) { return rand.Int(rand.Reader, big.NewInt(max)) } diff --git a/test/e2e/iam/atlas_org_api_key_access_list_test.go b/test/e2e/iam/atlas_org_api_key_access_list_test.go deleted file mode 100644 index 35e979c73b..0000000000 --- a/test/e2e/iam/atlas_org_api_key_access_list_test.go +++ /dev/null @@ -1,127 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasOrgAPIKeyAccessList(t *testing.T) { - cliPath, er := e2e.AtlasCLIBin() - require.NoError(t, er) - - apiKeyID, e := createOrgAPIKey() - require.NoError(t, e) - - t.Cleanup(func() { - require.NoError(t, deleteOrgAPIKey(apiKeyID)) - }) - - n, err := e2e.RandInt(255) - require.NoError(t, err) - - entry := fmt.Sprintf("192.168.0.%d", n) - - t.Run("Create", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - apiKeyAccessListEntity, - "create", - "--apiKey", - apiKeyID, - "--ip", - entry, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.PaginatedApiUserAccessList - require.NoError(t, json.Unmarshal(resp, &key)) - assert.NotEmpty(t, key.Results) - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - apiKeyAccessListEntity, - "list", - apiKeyID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.PaginatedApiUserAccessList - require.NoError(t, json.Unmarshal(resp, &key)) - assert.NotEmpty(t, key.Results) - }) - - t.Run("Delete", func(t *testing.T) { - deleteAtlasAccessListEntry(t, cliPath, entry, apiKeyID) - }) - - t.Run("Create Current IP", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - apiKeyAccessListEntity, - "create", - "--apiKey", - apiKeyID, - "--currentIp", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.PaginatedApiUserAccessList - require.NoError(t, json.Unmarshal(resp, &key)) - assert.NotEmpty(t, key.Results) - entry = *key.GetResults()[0].IpAddress - }) - - t.Run("Delete", func(t *testing.T) { - deleteAtlasAccessListEntry(t, cliPath, entry, apiKeyID) - }) -} - -func deleteAtlasAccessListEntry(t *testing.T, cliPath, entry, apiKeyID string) { - t.Helper() - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - apiKeyAccessListEntity, - "rm", - entry, - "--apiKey", - apiKeyID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("Access list entry '%s' deleted\n", entry) - assert.Equal(t, expected, string(resp)) -} diff --git a/test/e2e/iam/atlas_org_api_keys_test.go b/test/e2e/iam/atlas_org_api_keys_test.go deleted file mode 100644 index cc192da1fb..0000000000 --- a/test/e2e/iam/atlas_org_api_keys_test.go +++ /dev/null @@ -1,137 +0,0 @@ -// 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. -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasOrgAPIKeys(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - var ID string - - // This test must run first to grab the ID of the org to later describe - t.Run("Create", func(t *testing.T) { - desc := "e2e-test-atlas-org" - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "create", - "--desc", - desc, - "--role=ORG_READ_ONLY", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.ApiKeyUserDetails - require.NoError(t, json.Unmarshal(resp, &key)) - assert.Equal(t, desc, *key.Desc) - ID = *key.Id - }) - require.NotEmpty(t, ID) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var keys atlasv2.PaginatedApiApiUser - require.NoError(t, json.Unmarshal(resp, &keys)) - assert.NotEmpty(t, keys.Results) - }) - - t.Run("List Compact", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "ls", - "-c", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var keys []atlasv2.ApiKeyUserDetails - require.NoError(t, json.Unmarshal(resp, &keys)) - assert.NotEmpty(t, keys) - }) - - t.Run("Update", func(t *testing.T) { - const newDesc = "e2e-test-atlas-org-updated" - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "updates", - ID, - "--desc", - newDesc, - "--role=ORG_READ_ONLY", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.ApiKeyUserDetails - require.NoError(t, json.Unmarshal(resp, &key)) - assert.Equal(t, newDesc, *key.Desc) - }) - - t.Run("Describe", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "describe", - ID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var key atlasv2.ApiKeyUserDetails - require.NoError(t, json.Unmarshal(resp, &key)) - assert.Equal(t, ID, *key.Id) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - apiKeysEntity, - "rm", - ID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("API Key '%s' deleted\n", ID) - assert.Equal(t, expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_org_invitations_test.go b/test/e2e/iam/atlas_org_invitations_test.go deleted file mode 100644 index a0d839ebca..0000000000 --- a/test/e2e/iam/atlas_org_invitations_test.go +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2021 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. -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasOrgInvitations(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - require.NoError(t, err) - - n, err := e2e.RandInt(1000) - require.NoError(t, err) - - emailOrg := fmt.Sprintf("test-%v@mongodb.com", n) - var orgInvitationID string - - t.Run("Invite", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "invite", - emailOrg, - "--role", - "ORG_MEMBER", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - - var invitation admin.OrganizationInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailOrg, invitation.GetUsername()) - require.NotEmpty(t, invitation.GetId()) - orgInvitationID = invitation.GetId() - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - a := assert.New(t) - - var invitations []admin.OrganizationInvitation - require.NoError(t, json.Unmarshal(resp, &invitations)) - a.NotEmpty(invitations) - }) - - t.Run("Describe", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "get", - orgInvitationID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - a := assert.New(t) - - var invitation admin.OrganizationInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(orgInvitationID, invitation.GetId()) - a.Equal([]string{"ORG_MEMBER"}, invitation.GetRoles()) - }) - - t.Run("Update by email", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "update", - "--email", - emailOrg, - "--role", - roleNameOrg, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - a := assert.New(t) - - var invitation admin.OrganizationInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailOrg, invitation.GetUsername()) - a.ElementsMatch([]string{roleNameOrg}, invitation.GetRoles()) - }) - - t.Run("Update by ID", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "update", - orgInvitationID, - "--role", - roleNameOrg, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - a := assert.New(t) - var invitation admin.OrganizationInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailOrg, invitation.GetUsername()) - a.ElementsMatch([]string{roleNameOrg}, invitation.GetRoles()) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - invitationsEntity, - "delete", - orgInvitationID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("Invitation '%s' deleted\n", orgInvitationID) - a.Equal(expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_orgs_test.go b/test/e2e/iam/atlas_orgs_test.go deleted file mode 100644 index 5cd06f0f70..0000000000 --- a/test/e2e/iam/atlas_orgs_test.go +++ /dev/null @@ -1,134 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasOrgs(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - require.NoError(t, err) - - var orgID string - // This test must run first to grab the ID of the org to later describe - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err2 := cmd.CombinedOutput() - require.NoError(t, err2, string(resp)) - var orgs admin.PaginatedOrganization - err = json.Unmarshal(resp, &orgs) - require.NoError(t, err, string(resp)) - assert.NotEmpty(t, orgs.GetResults()) - orgID = orgs.GetResults()[0].GetId() - }) - require.NotEmpty(t, orgID) - - t.Run("Describe", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - "describe", - orgID, - "-o=json") - cmd.Env = os.Environ() - resp, err2 := cmd.CombinedOutput() - require.NoError(t, err2, string(resp)) - }) - - var userID string - t.Run("List Org Users", func(t *testing.T) { - cmd := exec.Command(cliPath, - orgEntity, - usersEntity, - "ls", - "--orgId", - orgID, - "-o=json") - cmd.Env = os.Environ() - resp, err2 := cmd.CombinedOutput() - require.NoError(t, err2, string(resp)) - var users admin.PaginatedApiAppUser - require.NoError(t, json.Unmarshal(resp, &users), string(resp)) - assert.NotEmpty(t, users.GetResults()) - userID = users.GetResults()[0].GetId() - }) - require.NotEmpty(t, userID) - - n, err := e2e.RandInt(255) - require.NoError(t, err) - orgName := fmt.Sprintf("e2e-org-%v", n) - var ( - publicAPIKey string - privateAPIKey string - ) - t.Run("Create", func(t *testing.T) { - t.Skip("Skipping create org e2e test, exceeded max number of linked orgs. Will reenable post cleanup") - cmd := exec.Command(cliPath, - orgEntity, - "create", - orgName, - "--ownerId", - userID, - "--apiKeyRole", - "ORG_OWNER", - "--apiKeyDescription", - "test", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var org admin.CreateOrganizationResponse - require.NoError(t, json.Unmarshal(resp, &org), string(resp)) - orgID = org.Organization.GetId() - publicAPIKey = org.ApiKey.GetPublicKey() - privateAPIKey = org.ApiKey.GetPrivateKey() - - require.NotEmpty(t, publicAPIKey) - require.NotEmpty(t, privateAPIKey) - }) - - t.Run("Delete", func(t *testing.T) { - t.Skip("Skipping delete org e2e test, exceeded max number of linked orgs. Will re-enable post cleanup") - if os.Getenv("MCLI_SERVICE") == "cloudgov" { - t.Skip("not available for gov") - } - t.Setenv("MCLI_PUBLIC_API_KEY", publicAPIKey) - t.Setenv("MCLI_PRIVATE_API_KEY", privateAPIKey) - cmd := exec.Command(cliPath, - orgEntity, - "delete", - orgID, - "--force", - ) - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_project_api_keys_test.go b/test/e2e/iam/atlas_project_api_keys_test.go deleted file mode 100644 index 51d201a235..0000000000 --- a/test/e2e/iam/atlas_project_api_keys_test.go +++ /dev/null @@ -1,133 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasProjectAPIKeys(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - var ID string - - // This test must run first to grab the ID of the project to later describe - t.Run("Create", func(t *testing.T) { - const desc = "e2e-test" - cmd := exec.Command(cliPath, - projectsEntity, - apiKeysEntity, - "create", - "--desc", - desc, - "--role=GROUP_READ_ONLY", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - var key atlasv2.ApiKeyUserDetails - require.NoError(t, json.Unmarshal(resp, &key)) - a.Equal(desc, *key.Desc) - ID = *key.Id - }) - require.NotEmpty(t, ID) - - defer func() { - if e := deleteOrgAPIKey(ID); e != nil { - t.Errorf("error deleting test apikey: %v", e) - } - }() - - t.Run("Assign", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - apiKeysEntity, - "assign", - ID, - "--role=GROUP_DATA_ACCESS_READ_ONLY", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - apiKeysEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - if err != nil { - t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) - } - var keys atlasv2.PaginatedApiApiUser - if err := json.Unmarshal(resp, &keys); err != nil { - t.Fatalf("unexpected error: %v", err) - } - assert.NotEmpty(t, keys.Results) - }) - - t.Run("List Compact", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - apiKeysEntity, - "ls", - "-c", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - if err != nil { - t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) - } - var keys []atlasv2.ApiKeyUserDetails - if err := json.Unmarshal(resp, &keys); err != nil { - t.Fatalf("unexpected error: %v", err) - } - assert.NotEmpty(t, keys) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - apiKeysEntity, - "rm", - ID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("API Key '%s' deleted\n", ID) - assert.Equal(t, expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_project_invitations_test.go b/test/e2e/iam/atlas_project_invitations_test.go deleted file mode 100644 index db654d774d..0000000000 --- a/test/e2e/iam/atlas_project_invitations_test.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2021 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. -//go:build e2e || (iam && !atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasProjectInvitations(t *testing.T) { - cliPath, err := e2e.Bin() - require.NoError(t, err) - - var invitationID string - - n, err := e2e.RandInt(1000) - require.NoError(t, err) - - projectName := fmt.Sprintf("e2e-proj-%v", n) - projectID, err := e2e.CreateProject(projectName) - require.NoError(t, err) - - emailProject := fmt.Sprintf("test-%v@mongodb.com", n) - t.Cleanup(func() { - e2e.DeleteProjectWithRetry(t, projectID) - }) - - t.Run("Invite", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "invite", - emailProject, - "--role", - "GROUP_READ_ONLY", - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var invitation admin.GroupInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailProject, invitation.GetUsername()) - require.NotEmpty(t, invitation.GetId()) - invitationID = invitation.GetId() - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "ls", - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var invitations []admin.GroupInvitation - require.NoError(t, json.Unmarshal(resp, &invitations)) - a.NotEmpty(invitations) - }) - - t.Run("Describe", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "get", - invitationID, - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var invitation admin.GroupInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(invitationID, invitation.GetId()) - a.Equal([]string{"GROUP_READ_ONLY"}, invitation.GetRoles()) - }) - - t.Run("Update by email", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "update", - "--email", - emailProject, - "--role", - roleName1, - "--role", - roleName2, - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var invitation admin.GroupInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailProject, invitation.GetUsername()) - a.ElementsMatch([]string{roleName1, roleName2}, invitation.GetRoles()) - }) - - t.Run("Update by ID", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "update", - invitationID, - "--role", - roleName1, - "--role", - roleName2, - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var invitation admin.GroupInvitation - require.NoError(t, json.Unmarshal(resp, &invitation)) - a.Equal(emailProject, invitation.GetUsername()) - a.ElementsMatch([]string{roleName1, roleName2}, invitation.GetRoles()) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - iamEntity, - projectsEntity, - invitationsEntity, - "delete", - invitationID, - "--force", - "--projectId", - projectID) - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("Invitation '%s' deleted\n", invitationID) - a.Equal(expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_project_teams_test.go b/test/e2e/iam/atlas_project_teams_test.go deleted file mode 100644 index 041e85cc64..0000000000 --- a/test/e2e/iam/atlas_project_teams_test.go +++ /dev/null @@ -1,144 +0,0 @@ -// 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. - -//go:build e2e || (iam && !om60 && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasProjectTeams(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - require.NoError(t, err) - - n, err := e2e.RandInt(1000) - require.NoError(t, err) - - projectName := fmt.Sprintf("e2e-proj-%v", n) - projectID, err := e2e.CreateProject(projectName) - require.NoError(t, err) - t.Cleanup(func() { - e2e.DeleteProjectWithRetry(t, projectID) - }) - - teamName := fmt.Sprintf("e2e-teams-%v", n) - teamID, err := createTeam(teamName) - require.NoError(t, err) - t.Cleanup(func() { - e := deleteTeam(teamID) - require.NoError(t, e) - }) - - t.Run("Add", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - teamsEntity, - "add", - teamID, - "--role", - "GROUP_READ_ONLY", - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - - var teams atlasv2.PaginatedTeamRole - require.NoError(t, json.Unmarshal(resp, &teams)) - found := false - for _, team := range teams.GetResults() { - if team.GetTeamId() == teamID { - found = true - break - } - } - a.True(found) - }) - - t.Run("Update", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - teamsEntity, - "update", - teamID, - "--role", - roleName1, - "--role", - roleName2, - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - - var roles atlasv2.PaginatedTeamRole - require.NoError(t, json.Unmarshal(resp, &roles)) - a.Len(roles.GetResults(), 1) - - role := roles.GetResults()[0] - a.Equal(teamID, role.GetTeamId()) - a.Len(role.GetRoleNames(), 2) - a.ElementsMatch([]string{roleName1, roleName2}, role.GetRoleNames()) - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - teamsEntity, - "ls", - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - - var teams atlasv2.PaginatedTeamRole - require.NoError(t, json.Unmarshal(resp, &teams)) - a.NotEmpty(teams.GetResults()) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - teamsEntity, - "delete", - teamID, - "--force", - "--projectId", - projectID) - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - a := assert.New(t) - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("Team '%s' deleted\n", teamID) - a.Equal(expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_projects_test.go b/test/e2e/iam/atlas_projects_test.go deleted file mode 100644 index 5c1af48931..0000000000 --- a/test/e2e/iam/atlas_projects_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/require" - "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasProjects(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - n, err := e2e.RandInt(1000) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - projectName := fmt.Sprintf("e2e-proj-%v", n) - - var projectID string - t.Run("Create", func(t *testing.T) { - // This depends on a ORG_ID ENV - cmd := exec.Command(cliPath, - projectsEntity, - "create", - projectName, - "--tag", "env=e2e", - "--tag", "prod=false", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - require.NoError(t, err, string(resp)) - - var project admin.Group - require.NoError(t, json.Unmarshal(resp, &project)) - if project.GetName() != projectName { - t.Errorf("got=%#v\nwant=%#v\n", project.Name, projectName) - } - projectID = project.GetId() - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - require.NoError(t, err, string(resp)) - }) - - t.Run("Describe", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - "describe", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - require.NoError(t, err, string(resp)) - }) - - t.Run("Tags", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - "describe", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var project admin.Group - if err := json.Unmarshal(resp, &project); err != nil { - t.Fatalf("unexpected error: %v", err) - } - - require.Len(t, project.GetTags(), 2) - - expectedTags := map[string]string{"env": "e2e", "prod": "false"} - for _, tag := range project.GetTags() { - expectedValue, ok := expectedTags[tag.GetKey()] - if !ok { - t.Errorf("unexpected tag key %s in tags: %v, expected tags: %v\n", tag.GetKey(), project.Tags, expectedTags) - } - - require.Equal(t, expectedValue, tag.GetValue()) - } - }) - - t.Run("Users", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - usersEntity, - "ls", - "--projectId", - projectID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - "delete", - projectID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - require.NoError(t, err, string(resp)) - - expected := fmt.Sprintf("Project '%s' deleted\n", projectID) - if string(resp) != expected { - t.Errorf("got=%#v\nwant=%#v\n", string(resp), expected) - } - }) -} diff --git a/test/e2e/iam/atlas_team_users_test.go b/test/e2e/iam/atlas_team_users_test.go deleted file mode 100644 index b8e7f9f1d4..0000000000 --- a/test/e2e/iam/atlas_team_users_test.go +++ /dev/null @@ -1,131 +0,0 @@ -// 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. - -//go:build e2e || (iam && !om60 && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasTeamUsers(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - require.NoError(t, err) - - n, err := e2e.RandInt(1000) - require.NoError(t, err) - - teamName := fmt.Sprintf("teams%v", n) - teamID, err := createTeam(teamName) - require.NoError(t, err) - defer func() { - if e := deleteTeam(teamID); e != nil { - t.Errorf("error deleting project: %v", e) - } - }() - - username, userID, err := OrgNUser(1) - require.NoError(t, err) - - t.Run("Add", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - usersEntity, - "add", - userID, - "--teamId", - teamID, - "-o=json", - ) - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - - var users atlasv2.PaginatedApiAppUser - require.NoError(t, json.Unmarshal(resp, &users)) - found := false - for _, user := range users.GetResults() { - if user.Username == username { - found = true - break - } - } - a.True(found) - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - usersEntity, - "ls", - "--teamId", - teamID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - var teams atlasv2.PaginatedApiAppUser - require.NoError(t, json.Unmarshal(resp, &teams)) - a.NotEmpty(teams.Results) - }) - - t.Run("List Compact", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - usersEntity, - "ls", - "-c", - "--teamId", - teamID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - a := assert.New(t) - var teams []atlasv2.CloudAppUser - require.NoError(t, json.Unmarshal(resp, &teams)) - a.NotEmpty(teams) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - usersEntity, - "delete", - userID, - "--teamId", - teamID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - a := assert.New(t) - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("User '%s' deleted from the team\n", userID) - a.Equal(expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_teams_test.go b/test/e2e/iam/atlas_teams_test.go deleted file mode 100644 index 212376b8da..0000000000 --- a/test/e2e/iam/atlas_teams_test.go +++ /dev/null @@ -1,163 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasTeams(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - n, err := e2e.RandInt(1000) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - teamName := fmt.Sprintf("teams%v", n) - var teamID string - - t.Run("Create", func(t *testing.T) { - username, _, err := OrgNUser(0) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - cmd := exec.Command(cliPath, - teamsEntity, - "create", - teamName, - "--username", - username, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - - a := assert.New(t) - require.NoError(t, err, string(resp)) - - var team atlasv2.Team - require.NoError(t, json.Unmarshal(resp, &team)) - a.Equal(teamName, team.Name) - teamID = team.GetId() - }) - require.NotEmpty(t, teamID) - - t.Run("Describe By ID", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - "describe", - "--id", - teamID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var team atlasv2.TeamResponse - require.NoError(t, json.Unmarshal(resp, &team)) - assert.Equal(t, teamID, team.GetId()) - }) - - t.Run("Describe By Name", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - "describe", - "--name", - teamName, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - var team atlasv2.TeamResponse - require.NoError(t, json.Unmarshal(resp, &team)) - assert.Equal(t, teamName, team.GetName()) - }) - - t.Run("Rename", func(t *testing.T) { - teamName += "_renamed" - cmd := exec.Command(cliPath, - teamsEntity, - "rename", - teamName, - "--teamId", - teamID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var team atlasv2.TeamResponse - require.NoError(t, json.Unmarshal(resp, &team)) - assert.Equal(t, teamID, team.GetId()) - assert.Equal(t, teamName, team.GetName()) - }) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - "ls", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var teams atlasv2.PaginatedTeam - require.NoError(t, json.Unmarshal(resp, &teams)) - assert.NotEmpty(t, teams.Results) - }) - - t.Run("List Compact", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - "ls", - "-c", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var teams []atlasv2.TeamResponse - require.NoError(t, json.Unmarshal(resp, &teams)) - assert.NotEmpty(t, teams) - }) - - t.Run("Delete", func(t *testing.T) { - cmd := exec.Command(cliPath, - teamsEntity, - "delete", - teamID, - "--force") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - expected := fmt.Sprintf("Team '%s' deleted\n", teamID) - assert.Equal(t, expected, string(resp)) - }) -} diff --git a/test/e2e/iam/atlas_users_test.go b/test/e2e/iam/atlas_users_test.go deleted file mode 100644 index ab85d03d62..0000000000 --- a/test/e2e/iam/atlas_users_test.go +++ /dev/null @@ -1,123 +0,0 @@ -// 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. - -//go:build e2e || (iam && atlas) - -package iam_test - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" -) - -func TestAtlasUsers(t *testing.T) { - cliPath, err := e2e.AtlasCLIBin() - require.NoError(t, err) - var ( - username string - userID string - orgID string - ) - - t.Run("List", func(t *testing.T) { - cmd := exec.Command(cliPath, - projectsEntity, - usersEntity, - "list", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var users atlasv2.PaginatedApiAppUser - require.NoError(t, json.Unmarshal(resp, &users), string(resp)) - require.NotEmpty(t, users.Results) - username = users.GetResults()[0].GetUsername() - userID = users.GetResults()[0].GetId() - }) - - t.Run("Describe by username", func(t *testing.T) { - cmd := exec.Command(cliPath, - usersEntity, - "describe", - "--username", - username, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var user atlasv2.CloudAppUser - require.NoError(t, json.Unmarshal(resp, &user), string(resp)) - assert.Equal(t, username, user.GetUsername()) - for i, item := range user.GetRoles() { - if item.HasOrgId() { - orgID = user.GetRoles()[i].GetOrgId() - break - } - } - require.NotEmpty(t, orgID) - }) - - t.Run("Describe by ID", func(t *testing.T) { - cmd := exec.Command(cliPath, - usersEntity, - "describe", - "--id", - userID, - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var user atlasv2.CloudAppUser - require.NoError(t, json.Unmarshal(resp, &user), string(resp)) - assert.Equal(t, userID, user.GetId()) - }) - - t.Run("Invite", func(t *testing.T) { - n, err := e2e.RandInt(10000) - require.NoError(t, err) - emailUser := fmt.Sprintf("cli-test-%v@moongodb.com", n) - t.Log("emailUser", emailUser, "orgID", orgID) - cmd := exec.Command(cliPath, - usersEntity, - "invite", - "--username", emailUser, - "--password", "**passW0rd**", - "--country", "US", - "--email", emailUser, - "--firstName", "TestFirstName", - "--lastName", "TestLastName", - "--orgRole", orgID+":ORG_READ_ONLY", - "-o=json") - cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) - - var user atlasv2.CloudAppUser - require.NoError(t, json.Unmarshal(resp, &user)) - assert.Equal(t, emailUser, user.GetUsername()) - assert.NotEmpty(t, user.GetId()) - assert.Empty(t, user.GetRoles()) // This is returned empty until the invite is accepted - }) -} diff --git a/test/e2e/iam/orgs_test.go b/test/e2e/iam/orgs_test.go index fea38930bd..398d3935bd 100644 --- a/test/e2e/iam/orgs_test.go +++ b/test/e2e/iam/orgs_test.go @@ -25,7 +25,7 @@ import ( "github.com/mongodb/mongodb-atlas-cli/mongocli/v2/test/e2e" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin" + "go.mongodb.org/ops-manager/opsmngr" ) func TestOrgs(t *testing.T) { @@ -44,11 +44,11 @@ func TestOrgs(t *testing.T) { cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() require.NoError(t, err, string(resp)) - var orgs atlasv2.PaginatedOrganization + var orgs opsmngr.Organizations err = json.Unmarshal(resp, &orgs) require.NoError(t, err, string(resp)) assert.NotEmpty(t, orgs.Results) - orgID = *orgs.GetResults()[0].Id + orgID = orgs.Results[0].ID require.NotEmpty(t, orgID, "orgID not set, resp: %s", resp) }) require.NotEmpty(t, orgID)