Open oscarhermoso opened 1 month ago
Update - I got my Sweeper working - but have some more feedback:
go test -v ./... -sweep=all
log.Printf
in some of the error handling, but these would only be visible if go test
was ran with the -v
flaggo test -v ./... -sweep-args=asdasd
-sweep string
List of Regions to run available Sweepers
-sweep-allow-failures
Enable to allow Sweeper Tests to continue after failures
-sweep-run string
Comma separated list of Sweeper Tests to run
And if someone else finds has the same issue - see below my working code below...
Create a `sweeper_test.tf` ```go // sweeper_test.tf package provider import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" // if your resources are in different packages, import here // _ "terraform-provider-example/internal/example" ) func TestMain(m *testing.M) { resource.TestMain(m) } ``` Extend your existing test files with an `init()` method: ```go // resource_example_test.tf package provider import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestExampleResource(t *testing.T) { // ... } // init is special, no issues with multiple init functions with same name func init() { resource.AddTestSweepers("example", &resource.Sweeper{ Name: "example", F: func(_ string) error { // ... } } ``` Run sweeper with: ```sh go test -v ./... -sweep=all ```
Does this documentation exist?
Where would you expect to find this documentation?
Description
I would like to follow an idiomatic example of Sweepers, so I can implement them for a provider that is based on the
terraform-plugin-framework
package.I'm fairly new to Go and creating Terraform providers; I have tried to follow the Terraform docs, but my sweepers do not run. (No need for you to debug my code, just trying to give some context.)
SWEEP
/SWEEP_ARGS
/SWEEP_DIR
based on unofficial GitHub code?) but these are not documentedregion
argument forSweeperFunc
TestMain
- I'm not sure if the name is important, or it could be replaced withTestWhatever
References
N/A