-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 details about skipping tests in VCR, and when this is needed #12407
base: main
Are you sure you want to change the base?
Conversation
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR hasn't generated any diffs, but I'll let you know if a future commit does. |
1 similar comment
This comment was marked as duplicate.
This comment was marked as duplicate.
@melinath This PR has been waiting for review for 3 weekdays. Please take a look! Use the label |
@@ -272,6 +272,51 @@ func TestSignatureAlgorithmDiffSuppress(t *testing.T) { | |||
} | |||
``` | |||
|
|||
## Skipping tests in VCR mode |
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.
style: task-based headings should use imperative
## Skipping tests in VCR mode | |
## Skip tests in VCR replaying mode |
@@ -272,6 +272,51 @@ func TestSignatureAlgorithmDiffSuppress(t *testing.T) { | |||
} | |||
``` | |||
|
|||
## Skipping tests in VCR mode | |||
|
|||
As described above, acceptance tests can be run in VCR modes where HTTP requests are either recorded or are replayed. This system can fail in some scenarios, so we will oftern flag tests that are incompatible with VCR so that they're skipped. This means the tests will not run automatically on PRs (in VCR mode) but the tests will still run in our nightly test suite. |
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.
As described above, acceptance tests can be run in VCR modes where HTTP requests are either recorded or are replayed. This system can fail in some scenarios, so we will oftern flag tests that are incompatible with VCR so that they're skipped. This means the tests will not run automatically on PRs (in VCR mode) but the tests will still run in our nightly test suite. | |
Acceptance tests are run in VCR replaying mode on PRs (using pre-recorded HTTP requests and responses) to reduce the time it takes to present results to contributors. However, not all resources or tests are possible to run in replaying mode. Incompatible tests should be skipped during VCR replaying mode. They will still run in our nightly test suite. |
|
||
As described above, acceptance tests can be run in VCR modes where HTTP requests are either recorded or are replayed. This system can fail in some scenarios, so we will oftern flag tests that are incompatible with VCR so that they're skipped. This means the tests will not run automatically on PRs (in VCR mode) but the tests will still run in our nightly test suite. | ||
|
||
### When should tests be skipped in VCR mode? |
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.
style: conceptual headings should use noun phrases
### When should tests be skipped in VCR mode? | |
### Reasons that tests are skipped in VCR replaying mode |
|
||
### When should tests be skipped in VCR mode? | ||
|
||
| Problem | Possible symptoms you'll see | How to fix/Other info | Skip in VCR? | |
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.
| Problem | Possible symptoms you'll see | How to fix/Other info | Skip in VCR? | | |
| Problem | Possible symptoms you'll see | How to fix/Other info | Skip in VCR replaying? | |
| Problem | Possible symptoms you'll see | How to fix/Other info | Skip in VCR? | | ||
| -------------- | ------------------------------- | ---------------------- |------------- | | ||
| Incorrect or insufficient data is present in VCR recordings to replay tests | Tests will fail with `Requested interaction not found` errors during REPLAYING mode | Make sure that you're not introducing randomness into the test, e.g. by unnecessarily using the random provider to set a resource's name.| If you cannot avoid this issue you should skip the test, but try to ensure that it cannot be fixed first.| | ||
| Bigtable acceptance tests aren't working in VCR mode | `Requested interaction not found` errors during REPLAYING mode | Currently the provider uses a separate client than the rest of the provider to interact with the Bigtable API. As HTTP traffic to the Bigtable API doesn't go via the shared client it cannot be recorded in RECORDING mode.| Skip the test in VCR ofr Bigtable. | |
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.
| Bigtable acceptance tests aren't working in VCR mode | `Requested interaction not found` errors during REPLAYING mode | Currently the provider uses a separate client than the rest of the provider to interact with the Bigtable API. As HTTP traffic to the Bigtable API doesn't go via the shared client it cannot be recorded in RECORDING mode.| Skip the test in VCR ofr Bigtable. | | |
| Bigtable acceptance tests aren't working in VCR mode | `Requested interaction not found` errors during REPLAYING mode | Currently the provider uses a separate client than the rest of the provider to interact with the Bigtable API. As HTTP traffic to the Bigtable API doesn't go via the shared client it cannot be recorded in RECORDING mode.| Skip the test in VCR for Bigtable. | |
| -------------- | ------------------------------- | ---------------------- |------------- | | ||
| Incorrect or insufficient data is present in VCR recordings to replay tests | Tests will fail with `Requested interaction not found` errors during REPLAYING mode | Make sure that you're not introducing randomness into the test, e.g. by unnecessarily using the random provider to set a resource's name.| If you cannot avoid this issue you should skip the test, but try to ensure that it cannot be fixed first.| | ||
| Bigtable acceptance tests aren't working in VCR mode | `Requested interaction not found` errors during REPLAYING mode | Currently the provider uses a separate client than the rest of the provider to interact with the Bigtable API. As HTTP traffic to the Bigtable API doesn't go via the shared client it cannot be recorded in RECORDING mode.| Skip the test in VCR ofr Bigtable. | | ||
| Using multiple provider aliases doesn't work in VCR | You may have two instances of the google provider in the test config but one of them doesn't seem to be using its provider arguments, e.g. using the wrong default project. | See this GitHub issue: https://github.com/hashicorp/terraform-provider-google/issues/20019 . The problem is that, due to how the VCR system works, one provider instance will be configured and the other will be forced to reuse the first instance's configuration, despite them being given different provider arguments. | Skip the test in VCR is using aliases is unavoidable. | |
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.
style: avoid e.g.
| Using multiple provider aliases doesn't work in VCR | You may have two instances of the google provider in the test config but one of them doesn't seem to be using its provider arguments, e.g. using the wrong default project. | See this GitHub issue: https://github.com/hashicorp/terraform-provider-google/issues/20019 . The problem is that, due to how the VCR system works, one provider instance will be configured and the other will be forced to reuse the first instance's configuration, despite them being given different provider arguments. | Skip the test in VCR is using aliases is unavoidable. | | |
| Using multiple provider aliases doesn't work in VCR | You may have two instances of the google provider in the test config but one of them doesn't seem to be using its provider arguments - for example, using the wrong default project. | See this GitHub issue: https://github.com/hashicorp/terraform-provider-google/issues/20019 . The problem is that, due to how the VCR system works, one provider instance will be configured and the other will be forced to reuse the first instance's configuration, despite them being given different provider arguments. | Skip the test in VCR is using aliases is unavoidable. | |
- When the provider is configured it will use credentials to obtain access tokens from GCP | ||
- Some acceptance tests use bootstrapping functions that ensure long-lived resources are present in a testing project before the provider is tested. | ||
|
||
Due to this you cannot use REPLAYING mode as a way to completely avoid HTTP traffic generally or with GCP APIs. |
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.
Due to this you cannot use REPLAYING mode as a way to completely avoid HTTP traffic generally or with GCP APIs. | |
These tests can still run in VCR replaying mode; however, REPLAYING mode can't be used as a way to completely avoid HTTP traffic generally or with GCP APIs. |
|
||
Due to this you cannot use REPLAYING mode as a way to completely avoid HTTP traffic generally or with GCP APIs. | ||
|
||
### How can tests be skipped in VCR mode? |
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.
style: prefer imperative headings
### How can tests be skipped in VCR mode? | |
### Skip tests in VCR replaying mode |
Since this duplicates the parent heading, I'd be inclined to merge this content into the parent heading (that is, above the "reasons" section)
|
||
### How can tests be skipped in VCR mode? | ||
|
||
You can make generated and handwritten tests be skipped in VCR mode. If possible, please include a code comment explaining the reason for skipping, or link to a GitHub issue. |
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.
You can make generated and handwritten tests be skipped in VCR mode. If possible, please include a code comment explaining the reason for skipping, or link to a GitHub issue. | |
If you skip a test in VCR mode, include a code comment explaining the reason for skipping (for example, a link to a GitHub issue.) |
Skipping acceptance tests that are generated from example files can be achieved by adding `skip_vcr: true` in the example's YAML: | ||
|
||
```yaml | ||
examples: | ||
- name: 'bigtable_app_profile_anycluster' | ||
... | ||
|
||
# bigtable instance does not use the shared HTTP client, this test creates an instance | ||
skip_vcr: true | ||
``` | ||
|
||
Skipping acceptance tests that are handwritten can be achieved by adding `acctest.SkipIfVcr(t)` at the start of the test: | ||
|
||
```go | ||
func TestAccPubsubTopic_update(t *testing.T) { | ||
acctest.SkipIfVcr(t) | ||
acctest.VcrTest(t, resource.TestCase{ ... } | ||
} | ||
``` |
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.
This would be great to wrap in tabs like
{{< tabs "create" >}} |
Thanks for the review, and the link to the developer docs style guide! I'll work through your comments tomorrow and this can be wrapped up after Thanksgiving 😁 |
Closes hashicorp/terraform-provider-google#20059
Release Note Template for Downstream PRs (will be copied)
See Write release notes for guidance.