Skip to content

Commit

Permalink
Merge branch 'main' into terraform-generate-provider-v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
willvedd authored Sep 22, 2023
2 parents 4eed1f4 + 1b93f15 commit b6ddfcf
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
61 changes: 46 additions & 15 deletions internal/cli/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func TestActionsPickerOptions(t *testing.T) {
})
}
}

func TestActionsInputSecretsToActionSecrets(t *testing.T) {
t.Run("it should map input secrets to action payload", func(t *testing.T) {
input := map[string]string{
Expand All @@ -218,22 +219,20 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) {
"secret3": "value3",
}
res := inputSecretsToActionSecrets(input)
expected := []management.ActionSecret{
{
Name: auth0.String("secret1"),
Value: auth0.String("value1"),
},
{
Name: auth0.String("secret2"),
Value: auth0.String("value2"),
},
{
Name: auth0.String("secret3"),
Value: auth0.String("value3"),
},
}

assert.Len(t, *res, 3)
assert.Equal(t, *res, expected)
assert.Contains(t, *res, management.ActionSecret{
Name: auth0.String("secret1"),
Value: auth0.String("value1"),
})
assert.Contains(t, *res, management.ActionSecret{
Name: auth0.String("secret2"),
Value: auth0.String("value2"),
})
assert.Contains(t, *res, management.ActionSecret{
Name: auth0.String("secret3"),
Value: auth0.String("value3"),
})
})

t.Run("it should handle empty input secrets", func(t *testing.T) {
Expand All @@ -244,3 +243,35 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) {
assert.Equal(t, res, &expected)
})
}
func TestActionsInputDependenciesToActionDependencies(t *testing.T) {
t.Run("it should map input dependencies to action payload", func(t *testing.T) {
input := map[string]string{
"fs-extra": "11.1.1",
"lodash": "4.0.0",
"uuid": "9.0.0",
}
res := inputDependenciesToActionDependencies(input)

assert.Len(t, *res, 3)
assert.Contains(t, *res, management.ActionDependency{
Name: auth0.String("fs-extra"),
Version: auth0.String("11.1.1"),
})
assert.Contains(t, *res, management.ActionDependency{
Name: auth0.String("lodash"),
Version: auth0.String("4.0.0"),
})
assert.Contains(t, *res, management.ActionDependency{
Name: auth0.String("uuid"),
Version: auth0.String("9.0.0"),
})
})

t.Run("it should handle empty input dependencies", func(t *testing.T) {
emptyInput := map[string]string{}
res := inputDependenciesToActionDependencies(emptyInput)
expected := []management.ActionDependency{}
assert.Len(t, *res, 0)
assert.Equal(t, expected, *res)
})
}
5 changes: 5 additions & 0 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"strings"

"github.com/auth0/go-auth0/management"
"github.com/google/uuid"
Expand Down Expand Up @@ -202,6 +203,10 @@ func (f *customDomainResourceFetcher) FetchData(ctx context.Context) (importData

customDomains, err := f.api.CustomDomain.List(ctx)
if err != nil {
if strings.Contains(err.Error(), "The account is not allowed to perform this operation, please contact our support team") {
return data, nil
}

return nil, err
}

Expand Down
20 changes: 20 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,26 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
_, err := fetcher.FetchData(context.Background())
assert.EqualError(t, err, "failed to list custom domains")
})

t.Run("it returns empty set error if unsupported feature error occurs", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
customDomainAPI.EXPECT().
List(gomock.Any()).
Return(nil, fmt.Errorf("403 Forbidden: The account is not allowed to perform this operation, please contact our support team"))

fetcher := customDomainResourceFetcher{
api: &auth0.API{
CustomDomain: customDomainAPI,
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Len(t, data, 0)
})
}

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

0 comments on commit b6ddfcf

Please sign in to comment.