Skip to content

Commit

Permalink
DXCDT-471: Enhance test sweep command (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Jun 20, 2023
1 parent ae0877c commit fc24db8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
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

0 comments on commit fc24db8

Please sign in to comment.