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

Add acceptance test generator #4819

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open

Conversation

musa-cf
Copy link

@musa-cf musa-cf commented Dec 27, 2024

Summary:

  • add go.work files to gitignore list
  • add test generation tool
  • add some guides relevant to acceptance tests and tool usage

Tool usage examples

Happy path example:

> go run cmd/acctestgen/main.go new_service

To be created:
- file: internal/services/new_service/data_source_test.go
- file: internal/services/new_service/resource_test.go
- dir: internal/services/new_service/testdata/
- file: internal/services/new_service/testdata/resourcebasicconfig.tf
- file: internal/services/new_service/testdata/datasourcebasicconfig.tf

Do you confirm that the file paths above are correct? [y|n]: y

The files have been created. To run the acceptance tests, you will need to first
set the necessary environment variables. See https://github.com/cloudflare/terraform-provider-cloudflare/blob/v4.39.0/contributing/environment-variable-dictionary.md
for the list of variables. The values will vary depending on the account and zone being used for
the tests. Once the environment variables are set, you can run the tests using the command:

TF_ACC=1 go test ./internal/services/new_service -run "^TestAccCloudflare" -v -count 1s

With -dryrun flag:

> go run cmd/acctestgen/main.go -dryrun new_service

To be created:
- file: internal/services/new_service/data_source_test.go
- file: internal/services/new_service/resource_test.go
- dir: internal/services/new_service/testdata/
- file: internal/services/new_service/testdata/resourcebasicconfig.tf
- file: internal/services/new_service/testdata/datasourcebasicconfig.tf


Dry-run mode is enabled.

To create the files, run this again without the 'dryrun' flag

Example: go run cmd/acctest/main.go new_service

Error case:

go run cmd/acctestgen/main.go -dryrun fwaefawef

ERROR: service 'fwaefawef' not found

exit status 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant