-
Notifications
You must be signed in to change notification settings - Fork 2.1k
autogeneration of tests for singular datasources #14872
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
autogeneration of tests for singular datasources #14872
Conversation
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 123 Click here to see the affected service packages
Action takenFound 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
1 similar comment
Tests analyticsTotal tests: 123 Click here to see the affected service packages
Action takenFound 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
|
🟢 Tests passed during RECORDING mode: 🟢 No issues found for passed tests after REPLAYING rerun. 🔴 Tests failed during RECORDING mode: 🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR. |
|
🟢 Tests passed during RECORDING mode: 🟢 No issues found for passed tests after REPLAYING rerun. 🔴 Tests failed during RECORDING mode: 🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR. |
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 35 Click here to see the affected service packages
🟢 All tests passed! View the build log |
|
Hello! I am a robot. Tests will require approval from a repository maintainer to run. Googlers: For automatic test runs see go/terraform-auto-test-runs. @melinath, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
melinath
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than converting a new datasource to have generated tests, could you take a resource that already has a generated datasource and convert its tests?
Ideally, it would be nice to rename the handwritten test file to have the same name as the generated file in a separate PR, then remove the handwritten test file in this PR. That would make the diff easier to review.
mmv1/products/redis/Cluster.yaml
Outdated
| autogen_async: true | ||
| datasource: | ||
| generate: true | ||
| generate_tests: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given there are only four datasources generated at the moment, could we actually just convert all four in this PR (with simplified diffs) and make that the default behavior, instead of having a generate_tests flag that needs to be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the problem with this is that there are generatable datasources (ie storagecontrol) that don't have generatable tests, as they only have handrolled tests, so no real way of generating from that template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we probably want to have an exclude_test attribute that you can set to not generate, similar to the exclude_docs & exclude_test for examples, which defaults to false.
The alternative would be to make generate_test default to true (advantage being that we wouldn't end up with a double-negative) but we generally try to avoid that at the moment (I forget why - maybe hard to tell the difference between "unset" and "set to false"?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, the default behavior should be "generate tests" since that's what we expect people to do in most cases.
I can for certain datasources yeah, I think it might best to keep the flag(so datasources with handrolled resource tests are compatible), but still replacing tests for compatible datasources such as the redis/iapclient ones done in this PR, let me know if you think this isn't the right way |
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 121 Click here to see the affected service packages
Action takenFound 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
| if err := os.MkdirAll(targetFolder, os.ModePerm); err != nil { | ||
| log.Println(fmt.Errorf("error creating parent directory %v: %v", targetFolder, err)) | ||
| } | ||
| targetFilePath := path.Join(targetFolder, fmt.Sprintf("data_source_%s_test.go", t.ResourceGoFilename(object))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 doing this for now so the diff is clearer seems reasonable - we should switch to _generated_test.go in the near future, but that can be in a separate PR.
mmv1/templates/terraform/examples/base_configs/datasource_test_file.go.tmpl
Show resolved
Hide resolved
| {{ $fieldName }} = {{ $e.ResourceType $.Res.TerraformName }}.{{ $e.PrimaryResourceId }}.{{ $fieldName }} | ||
| {{- end }} | ||
| }`, | ||
| testAcc{{ $e.TestSlug $.Res.ProductMetadata.Name $.Res.Name }}(context), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably inline the configuration (similar to what IAM tests do) rather than using string formatting - string formatting like this makes it harder to read the final result (both for humans and for the missing test detector).
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 121 Click here to see the affected service packages
Action takenFound 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
|
I think this is probably working but it's hard to tell because the test runs were interleaved. Rerunning. /gcbrun |
This comment was marked as outdated.
This comment was marked as outdated.
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 103 Click here to see the affected service packages
🟢 All tests passed! View the build log |
melinath
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, diff looks correct
d6166b5
…#14872) Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
…#14872) Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
…#14872) Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
hashicorp/terraform-provider-google#12595 part of this initiative
Release Note Template for Downstream PRs (will be copied)
See Write release notes for guidance.