-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DXCDT-471: Enhance test sweep command (#644)
- Loading branch information
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
) | ||
|
||
func init() { | ||
Actions() | ||
Clients() | ||
Connections() | ||
CustomDomains() | ||
|