-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding State Checks for Known Type and Value, and Sensitive Checks (#275
) * Adding StateCheck interface (#266) * Configuring when state checks are executed. * Testing that state checks are executed. * Adding validation to ensure state checks are only defined for config (apply) tests (#266) * Adding ExpectKnownValue state check (#266) * Adding ExpectKnownOutputValue state check (#266) * Adding ExpectKnownOutputValueAtPath state check (#266) * Modifying ExpectKnown<Value|OutputValue|OutputValueAtPath> to allow for checking of null values (#266) * Adding ExpectSensitiveValue state check (#266) * Adding documentation for state checks and null known value check type (#266) * Adding to the documentation for the custom known value check (#266) * Adding changelog entries (#266) * Refactoring to use updated known value check types (#266) * Correcting documentation for revised naming of known value check types (#266) * Renaming nul known value check (#266) * Fixing tests (#266) * Adding address and path to state check errors (#266) * Fixing navigation (#266) * Fixing changelog entries * Modifying ExpectKnown<Value|OutputValue|OutputValueAtPath> to handle null checking (#266) * Deprecating ExpectNullOutputValue and ExpectNullOutputValueAtPath plan checks (#266) * Adding return statements (#266) * Adding change log entry for deprecation of `ExpectNullOutputValue` and `ExpectNullOutputValueAtPath` plan checks (#266) * Modifying return value of nullExact.String() (#266) * Renaming variable (#266) * Adding comment for Terraform v1.4.6 (#266) * Adding further tests for null exact known value type check (#266) * Linting (#266) * Renaming BoolExact to Bool, and NullExact to Null (#266) * Removing ConfigStateChecks type (#266) * Move execution of ConfigStateChecks (#266)
- Loading branch information
1 parent
f0cbf8e
commit 1b803b4
Showing
55 changed files
with
6,187 additions
and
309 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'statecheck: Introduced new `statecheck` package with interface and built-in | ||
state check functionality' | ||
time: 2024-01-11T14:21:26.261094Z | ||
custom: | ||
Issue: "275" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'statecheck: Added `ExpectKnownValue` state check, which asserts that a given | ||
resource attribute has a defined type, and value' | ||
time: 2024-01-11T14:22:23.072321Z | ||
custom: | ||
Issue: "275" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'statecheck: Added `ExpectKnownOutputValue` state check, which asserts that | ||
a given output value has a defined type, and value' | ||
time: 2024-01-11T14:23:14.025585Z | ||
custom: | ||
Issue: "275" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'statecheck: Added `ExpectKnownOutputValueAtPath` plan check, which asserts | ||
that a given output value at a specified path has a defined type, and value' | ||
time: 2024-01-11T14:23:53.633255Z | ||
custom: | ||
Issue: "275" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'statecheck: Added `ExpectSensitiveValue` built-in state check, which asserts | ||
that a given attribute has a sensitive value' | ||
time: 2024-01-11T14:25:44.598583Z | ||
custom: | ||
Issue: "275" |
This file contains 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,7 @@ | ||
kind: NOTES | ||
body: 'plancheck: Deprecated `ExpectNullOutputValue` and `ExpectNullOutputValueAtPath`. | ||
Use `ExpectKnownOutputValue` and `ExpectKnownOutputValueAtPath` with | ||
`knownvalue.NullExact` instead' | ||
time: 2024-01-22T08:26:28.053303Z | ||
custom: | ||
Issue: "275" |
This file contains 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,29 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package resource | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
tfjson "github.com/hashicorp/terraform-json" | ||
"github.com/mitchellh/go-testing-interface" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
) | ||
|
||
func runStateChecks(ctx context.Context, t testing.T, state *tfjson.State, stateChecks []statecheck.StateCheck) error { | ||
t.Helper() | ||
|
||
var result []error | ||
|
||
for _, stateCheck := range stateChecks { | ||
resp := statecheck.CheckStateResponse{} | ||
stateCheck.CheckState(ctx, statecheck.CheckStateRequest{State: state}, &resp) | ||
|
||
result = append(result, resp.Error) | ||
} | ||
|
||
return errors.Join(result...) | ||
} |
This file contains 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,22 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package resource | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
) | ||
|
||
var _ statecheck.StateCheck = &stateCheckSpy{} | ||
|
||
type stateCheckSpy struct { | ||
err error | ||
called bool | ||
} | ||
|
||
func (s *stateCheckSpy) CheckState(ctx context.Context, req statecheck.CheckStateRequest, resp *statecheck.CheckStateResponse) { | ||
s.called = true | ||
resp.Error = s.err | ||
} |
This file contains 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 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 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 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 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 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.