Skip to content

Commit

Permalink
CLOUDP-194831: Fix and validate templates for all cloud provider acce…
Browse files Browse the repository at this point in the history
…ss commands (#2151)
  • Loading branch information
gssbzn authored Aug 11, 2023
1 parent 561911e commit 74714d3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

AWS IAM role '<CloudProviderAccessAWSIAMRole.RoleId> successfully authorized.
AWS IAM role '<RoleId> successfully authorized.


Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

AWS IAM role '<CloudProviderAccessAWSIAMRole.RoleId>' successfully created.
Atlas AWS Account ARN: <CloudProviderAccessAWSIAMRole.AtlasAWSAccountArn>
Unique External ID: <CloudProviderAccessAWSIAMRole.AtlasAssumedRoleExternalId>
AWS IAM role '<RoleId>' successfully created.
Atlas AWS Account ARN: <AtlasAWSAccountArn>
Unique External ID: <AtlasAssumedRoleExternalId>


Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

AWS IAM role '<CloudProviderAccessAWSIAMRole.RoleId> successfully authorized.
AWS IAM role '<RoleId> successfully authorized.


Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ If the command succeeds, the CLI returns output similar to the following sample.

.. code-block::

AWS IAM role '<CloudProviderAccessAWSIAMRole.RoleId>' successfully created.
Atlas AWS Account ARN: <CloudProviderAccessAWSIAMRole.AtlasAWSAccountArn>
Unique External ID: <CloudProviderAccessAWSIAMRole.AtlasAssumedRoleExternalId>
AWS IAM role '<RoleId>' successfully created.
Atlas AWS Account ARN: <AtlasAWSAccountArn>
Unique External ID: <AtlasAssumedRoleExternalId>


Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const authorizeTemplate = "AWS IAM role '{{.CloudProviderAccessAWSIAMRole.RoleId}} successfully authorized.\n"
const authorizeTemplate = "AWS IAM role '{{.RoleId}} successfully authorized.\n"

type AuthorizeOpts struct {
cli.GlobalOpts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/require"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201004/admin"
)

func TestAuthorizeTemplate(t *testing.T) {
test.VerifyOutputTemplate(t, authorizeTemplate, atlasv2.CloudProviderAccessRole{})
}

func TestAuthorizeOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderAccessRoleAuthorizer(ctrl)
Expand All @@ -41,10 +46,7 @@ func TestAuthorizeOpts_Run(t *testing.T) {
AuthorizeCloudProviderAccessRole(opts.ProjectID, opts.roleID, opts.newCloudProviderAuthorizationRequest()).
Return(expected, nil).
Times(1)

if err := opts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
require.NoError(t, opts.Run())
}

func TestAuthorizeBuilder(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/atlas/cloudproviders/accessroles/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

const (
provider = "AWS"
createTemplate = `AWS IAM role '{{.CloudProviderAccessAWSIAMRole.RoleId}}' successfully created.
Atlas AWS Account ARN: {{.CloudProviderAccessAWSIAMRole.AtlasAWSAccountArn}}
Unique External ID: {{.CloudProviderAccessAWSIAMRole.AtlasAssumedRoleExternalId}}
createTemplate = `AWS IAM role '{{.RoleId}}' successfully created.
Atlas AWS Account ARN: {{.AtlasAWSAccountArn}}
Unique External ID: {{.AtlasAssumedRoleExternalId}}
`
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/require"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201004/admin"
)

func TestCreateTemplate(t *testing.T) {
test.VerifyOutputTemplate(t, createTemplate, atlasv2.CloudProviderAccessRole{})
}

func TestCreateOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderAccessRoleCreator(ctrl)
Expand All @@ -42,9 +47,7 @@ func TestCreateOpts_Run(t *testing.T) {
Return(expected, nil).
Times(1)

if err := createOpts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
require.NoError(t, createOpts.Run())
}

func TestCreateBuilder(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/require"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201004/admin"
)

func TestDeauthorizeTemplate(t *testing.T) {
t.Run("success", func(t *testing.T) {
test.VerifyOutputTemplate(t, deauthorizeSuccess, atlasv2.CloudProviderAccessRole{})
})
t.Run("fail", func(t *testing.T) {
test.VerifyOutputTemplate(t, deauthorizeFail, atlasv2.CloudProviderAccessRole{})
})
}

func TestDeauthorizeOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderAccessRoleDeauthorizer(ctrl)
Expand All @@ -44,9 +55,7 @@ func TestDeauthorizeOpts_Run(t *testing.T) {
Return(nil).
Times(1)

if err := opts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
require.NoError(t, opts.Run())
}

func TestDeauthorizeBuilder(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions internal/cli/atlas/cloudproviders/accessroles/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"github.com/stretchr/testify/require"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201004/admin"
)

func TestListTemplate_Run(t *testing.T) {
test.VerifyOutputTemplate(t, listTemplate, atlasv2.CloudProviderAccessRoles{})
}

func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderAccessRoleLister(ctrl)
Expand Down Expand Up @@ -58,12 +63,8 @@ func TestList_Run(t *testing.T) {
Return(expected, nil).
Times(1)

if err := listOpts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}

require.NoError(t, listOpts.Run())
t.Log(buf.String())
test.VerifyOutputTemplate(t, listTemplate, expected)
}

func TestListBuilder(t *testing.T) {
Expand Down

0 comments on commit 74714d3

Please sign in to comment.