Skip to content

Commit

Permalink
Add test for tagRegistryCredentials()
Browse files Browse the repository at this point in the history
  • Loading branch information
PettitWesley committed Jan 29, 2019
1 parent c6a2c8a commit 2bc76eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ecs-cli/modules/cli/regcreds/regcreds_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func Up(c *cli.Context) {
}

if len(tags) > 0 {
err = tagRegistryCredentials(credentialOutput, roleName, tags, commandConfig)
taggingClient := tagging.NewTaggingClient(commandConfig)
err = tagRegistryCredentials(credentialOutput, tags, taggingClient)
if err != nil {
log.Fatal("Failed to tag resources: ", err)
}
Expand Down Expand Up @@ -326,14 +327,13 @@ func validateOutputOptions(outputDir string, skipOutput bool) error {
return nil
}

func tagRegistryCredentials(creds map[string]regcredio.CredsOutputEntry, roleName string, tags map[string]*string, commandConfig *config.CommandConfig) error {
func tagRegistryCredentials(creds map[string]regcredio.CredsOutputEntry, tags map[string]*string, taggingClient tagging.Client) error {
var arns []*string

for _, credInfo := range creds {
arns = append(arns, aws.String(credInfo.CredentialARN))
}

taggingClient := tagging.NewTaggingClient(commandConfig)
input := &resourcegroupstaggingapi.TagResourcesInput{
ResourceARNList: arns,
Tags: tags,
Expand Down
30 changes: 30 additions & 0 deletions ecs-cli/modules/cli/regcreds/regcreds_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/iam/mock"
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/kms/mock"
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/secretsmanager/mock"
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/tagging/mock"
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils/regcredio"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
secretsmanager "github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/golang/mock/gomock"
"github.com/pkg/errors"
Expand Down Expand Up @@ -216,6 +218,34 @@ func TestGetOrCreateRegistryCredentials_ErrorOnUpdate(t *testing.T) {
assert.Error(t, err)
}

func TestTagRegistryCredentials(t *testing.T) {
creds := map[string]regcredio.CredsOutputEntry{
"the-who-registry.com": regcredio.CredsOutputEntry{
CredentialARN: "arn:aws:secretsmanager:eu-west-1:111111111111:secret:path/whoareyou-1978",
},
}

tags := map[string]*string{
"Baba": aws.String("O'riley"),
"Eminence": aws.String("Front"),
"My": aws.String("Generation"),
}

ctrl := gomock.NewController(t)

mockTagging := mock_tagging.NewMockClient(ctrl)

gomock.InOrder(
mockTagging.EXPECT().TagResources(gomock.Any()).Do(func(x interface{}) {
input := x.(*resourcegroupstaggingapi.TagResourcesInput)
assert.Equal(t, tags, input.Tags, "Expected tags to match")
}).Return(&resourcegroupstaggingapi.TagResourcesOutput{}, nil),
)

err := tagRegistryCredentials(creds, tags, mockTagging)
assert.NoError(t, err, "Unexpected error calling tagRegistryCredentials")
}

func TestValidateCredsInput_ErrorEmptyCreds(t *testing.T) {
emptyCredMap := make(map[string]regcredio.RegistryCredEntry)
emptyCredsInput := regcredio.ECSRegCredsInput{
Expand Down

0 comments on commit 2bc76eb

Please sign in to comment.