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

Merged
merged 9 commits into from
Jan 8, 2025
Merged

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

Copy link
Member

@jacobbednarz jacobbednarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at a high level, i'm 👍 . two things we should do though to make the UX more consistent here are:

  1. we move this into tools/ given we aren't expecting the consumer of the library to use this. it's internal only and should be stripped from the end package that terraform consumes. check out the current master version of this for some inspiration.
  2. this should be wrapped in a scripts/... execution. the goal of the scripts directory is to have a unified interface with how we expose tooling to operators. a deeper read on this is at https://github.com/github/scripts-to-rule-them-all but in essence, it means we maintain this pattern for all of the repositories.

cmd/acctestgen/main.go Outdated Show resolved Hide resolved
cmd/acctestgen/main.go Outdated Show resolved Hide resolved
cmd/acctestgen/main.go Outdated Show resolved Hide resolved
cmd/acctestgen/main.go Outdated Show resolved Hide resolved
musa-cf and others added 3 commits January 3, 2025 14:22
Co-authored-by: Jacob Bednarz <jacob.bednarz@hey.com>
Co-authored-by: Jacob Bednarz <jacob.bednarz@hey.com>
@musa-cf
Copy link
Author

musa-cf commented Jan 3, 2025

@jacobbednarz Thanks for the feedback! I've pushed a new commit with your suggestions.

@jacobbednarz jacobbednarz merged commit 6d39c66 into cloudflare:next Jan 8, 2025
0 of 2 checks passed
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.

2 participants