-
Notifications
You must be signed in to change notification settings - Fork 16
Add ability to test whether warnings are raised during test steps #17
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
Closed
Closed
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
569231b
Piping output from terraform apply into stdout.txt in working directo…
bendbennett 1d91315
Add test to verify that warnings are generated during test step execu…
bendbennett 5c1b67e
Moving defer file.Close outside for loop (#16)
bendbennett 71f0877
Updating defer func to log error and fail test if closing file contai…
bendbennett 1061d08
Inspecting streaming json output for warnings, and error and streamin…
bendbennett 4cac99e
Switching to using streaming json for terraform refresh (#16)
bendbennett 021c2e8
Use framework testprovider files for setup of test using ProtoV5Provi…
bendbennett 5e649d3
Temporarily use terraform-exec sha (#16)
bendbennett 9a77e42
Using CreatePlanJSON() for generating streaming JSON output when runn…
bendbennett f496bfe
Refactoring stdout related functions (#16)
bendbennett 9a154c6
Merge branch 'main' into bendbennett/issues-16
bendbennett da0f4e9
Fallback to using standard terraform-exec commands (e.g., Apply() rat…
bendbennett 554cbd9
Updating test coverage for apply, plan, refresh and destroy (#16)
bendbennett 89be0c3
Switching to using bytes.Buffer for terraform-exec streaming json out…
bendbennett ad2edeb
Adding changelog entry and updating documentation (#16)
bendbennett 28c6676
Adding ExpectNonEmptyPlan to TestTest_TestStep_ProviderFactories_Expe…
bendbennett 3ccd606
Removing unused method (#16)
bendbennett af3a9dd
Renaming struct from Stdout to TerraformJSONBuffer (#16)
bendbennett 74ea0f6
Adding Parse() function to TerraformJSONBuffer and separating out tfj…
bendbennett e93c329
Using file for test fixture (#16)
bendbennett 32cb527
Refactored to use command-specific responses and to instantiate insta…
bendbennett 72c60c0
Joining strings for error output (#16)
bendbennett 9357173
Returning response structs for testStepNewRefreshState() and testStep…
bendbennett a12aaa1
Bumping to latest main for terraform-exec (#16)
bendbennett 2fb79ba
Adding contents of error diagnostics to error supplied to TestCase Er…
bendbennett ad5ebb1
Supplying stdout to test output (#16)
bendbennett a30a88f
Renaming vars (#16)
bendbennett 870e540
Return diagnostics rather than the whole of stdout (#16)
bendbennett 25b4681
Only return error diagnostics for errors and warning diagnostics for …
bendbennett d27b6c2
Return errors rather than log and exit. Remove usage of TFJSON stdout…
bendbennett 1369356
Switching to using bufio.NewReader in order to be able to handle line…
bendbennett bba2711
Adding NewTerraformJSONBufferFromFile and ReadFile funcs (#16)
bendbennett d96eb7c
Merge branch 'main' into bendbennett/issues-16
bendbennett bc8bc6d
Linting (#16)
bendbennett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
kind: FEATURES | ||
body: 'helper/resource: Added `TestStep` type `ExpectWarning` field, which enables | ||
verifying that a warning has been emitted during plan, apply, refresh and destroy. | ||
Requires that Terraform 0.15.3 or later is used as it makes use of the Terraform | ||
[machine-readable UI](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)' | ||
time: 2023-01-18T08:32:04.688764Z | ||
custom: | ||
Issue: "16" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For others benefit, the
TestCase.ErrorCheck
functionality is the main wrinkle that prevents us from immediately being able to use Terraform's machine readable output (JSON view/UI).ErrorCheck
functionality, currently used in many popular Terraform provider acceptance tests, was intended to serve these use cases:Today the testing code is reliant on terraform-exec's
error
returns to include the data needed forTestCase.ErrorCheck
andTestStep.ExpectError
functionality to work. Warning diagnostics are not passed back the same way, since they are not errors and should not stop program execution. In order to capture similar data for warnings, the testing code would either need to perform error-prone (and likely version dependent) scraping of the human-readable output or switch to the machine-readable output. The machine-readable output means that theerror
from terraform-exec needs to be fundamentally treated differently and trying to convert machine-readable error diagnostics to be functionally equivalent to the priorerror
would be a non-trivial exercise that's not guaranteed to fully keep backwards compatibility.An approach to this situation may be to prevent defining both
TestCase.ErrorCheck
and the newTestStep.ExpectWarning
in the sameTestCase
, and setting up the testing execution to continue using the human-readable output whereErrorCheck
is used. This is a non-starter for providers such as the Terraform AWS Provider though, which definesErrorCheck
functionality on all tests, meaningExpectWarning
could never be used.Definitely open to ideas here, but trying to work around this further is risky at best.