Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-471: Enhance test sweep command #644

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test-sweep: ## Clean up test tenant
${call print_warning, "WARNING: This will destroy infrastructure. Use only in development accounts."}
@read -p "Continue? [y/N] " ans && ans=$${ans:-N} ; \
if [ $${ans} = y ] || [ $${ans} = Y ]; then \
go test ./internal/acctest/sweep -v -sweep="phony" $(SWEEPARGS) ; \
go test ./internal/acctest/sweep -v -sweep="${AUTH0_DOMAIN}" $(SWEEPARGS) ; \
fi

#-----------------------------------------------------------------------------------------------------------------------
Expand Down
50 changes: 50 additions & 0 deletions internal/acctest/sweep/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sweep

import (
"log"
"strings"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

// Actions will run a test sweeper to remove all Auth0 Actions created through tests.
func Actions() {
resource.AddTestSweepers("auth0_actions", &resource.Sweeper{
Name: "auth0_actions",
F: func(_ string) error {
api, err := auth0API()
if err != nil {
return err
}

var page int
var result *multierror.Error
for {
actionList, err := api.Action.List(management.Page(page))
if err != nil {
return err
}

for _, action := range actionList.Actions {
log.Printf("[DEBUG] ➝ %s", action.GetName())

if strings.Contains(action.GetName(), "Test") {
result = multierror.Append(
result,
api.Action.Delete(action.GetID()),
)
log.Printf("[DEBUG] ✗ %s", action.GetName())
}
}
if !actionList.HasNext() {
break
}
page++
}

return result.ErrorOrNil()
},
})
}
2 changes: 1 addition & 1 deletion internal/acctest/sweep/custom_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CustomDomains() {
for _, domain := range domains {
log.Printf("[DEBUG] ➝ %s", domain.GetDomain())

if strings.Contains(domain.GetDomain(), "auth.uat.terraform-provider-auth0.com") {
if strings.Contains(domain.GetDomain(), "auth.terraform-provider-auth0.com") {
result = multierror.Append(
result,
api.CustomDomain.Delete(domain.GetID()),
Expand Down
1 change: 1 addition & 0 deletions internal/acctest/sweep/sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func init() {
Actions()
Clients()
Connections()
CustomDomains()
Expand Down