Skip to content

Commit b415e8f

Browse files
Address @deiga test conventions feedback
Add a 'terraform-plugin-testing Conventions' section to .github/instructions/tests.instructions.md covering: - Prefer ConfigStateChecks over the legacy Check / ComposeTestCheckFunc pattern. - Use ValueComparers (compare.ValuesSame / compare.ValuesDiffer) for cross-step value comparisons instead of custom pointer structs. - Don't flag legacy patterns in unmodified tests; only in new or substantially modified ones. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 96bacb6 commit b415e8f

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

.github/instructions/tests.instructions.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ checklist in `.github/copilot-instructions.md`.
2727
- Avoid hardcoded secrets or tokens in test files; use environment variables
2828
or test helpers.
2929

30+
## terraform-plugin-testing Conventions
31+
32+
Tests in this repo use
33+
[`github.com/hashicorp/terraform-plugin-testing`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing)
34+
and follow its modern conventions. Hold new and changed tests to these
35+
patterns:
36+
37+
- Prefer `ConfigStateChecks` (state-check functions from the
38+
`statecheck` package) over the older `Check` /
39+
`resource.ComposeTestCheckFunc` pattern. Flag new `TestStep`s that
40+
use `Check` with the legacy `resource.TestCheckResourceAttr*` helpers
41+
when an equivalent `statecheck` exists.
42+
- For comparing values across steps (e.g. to assert a value did or did
43+
not change between Apply runs), use
44+
[`ValueComparers`](https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/value-comparers)
45+
via `compare.ValuesSame` / `compare.ValuesDiffer` instead of the older
46+
pattern of stashing pointers to attribute values in custom structs and
47+
comparing them by hand.
48+
- Existing tests using the legacy `Check` pattern do not need to be
49+
rewritten as part of an unrelated change. Only flag the legacy pattern
50+
in new tests, or in tests that are being substantially modified.
51+
3052
## When Reviewing Test Changes
3153

3254
- If a test was deleted or weakened, explain why in the report and flag as

0 commit comments

Comments
 (0)