Commit graph

77 commits

Author SHA1 Message Date
Samsondeen
0b35407d2c
Allow functions in test mock blocks (#37883)
Some checks failed
build / Build for freebsd_amd64 (push) Has been cancelled
build / Build for linux_amd64 (push) Has been cancelled
build / Build for openbsd_amd64 (push) Has been cancelled
build / Build for solaris_amd64 (push) Has been cancelled
build / Build for windows_amd64 (push) Has been cancelled
build / Build for freebsd_arm (push) Has been cancelled
build / Build for linux_arm (push) Has been cancelled
build / Build for darwin_arm64 (push) Has been cancelled
build / Build for linux_arm64 (push) Has been cancelled
build / Build for windows_arm64 (push) Has been cancelled
build / Build Docker image for linux_386 (push) Has been cancelled
build / Build Docker image for linux_amd64 (push) Has been cancelled
build / Build Docker image for linux_arm (push) Has been cancelled
build / Build Docker image for linux_arm64 (push) Has been cancelled
build / Build e2etest for linux_386 (push) Has been cancelled
build / Build e2etest for windows_386 (push) Has been cancelled
build / Build e2etest for darwin_amd64 (push) Has been cancelled
build / Build e2etest for linux_amd64 (push) Has been cancelled
build / Build e2etest for windows_amd64 (push) Has been cancelled
build / Build e2etest for linux_arm (push) Has been cancelled
build / Build e2etest for darwin_arm64 (push) Has been cancelled
build / Build e2etest for linux_arm64 (push) Has been cancelled
build / Run e2e test for linux_386 (push) Has been cancelled
build / Run e2e test for windows_386 (push) Has been cancelled
build / Run e2e test for darwin_amd64 (push) Has been cancelled
build / Run e2e test for linux_amd64 (push) Has been cancelled
build / Run e2e test for windows_amd64 (push) Has been cancelled
build / Run e2e test for linux_arm (push) Has been cancelled
build / Run e2e test for linux_arm64 (push) Has been cancelled
build / Run terraform-exec test for linux amd64 (push) Has been cancelled
2026-01-22 09:42:21 +01:00
Max Qian
078ac7cb21
fix: TestTest_Parallel adds delay to ensure order (#37890)
Signed-off-by: Max Qian <zq2@illinois.edu>
2025-11-11 13:47:26 +01:00
Liam Cervante
e44b870b8b
don't write ephemeral outputs to state (#37821)
Some checks failed
build / Build for freebsd_amd64 (push) Has been cancelled
build / Build for linux_amd64 (push) Has been cancelled
build / Build for openbsd_amd64 (push) Has been cancelled
build / Build for solaris_amd64 (push) Has been cancelled
build / Build for windows_amd64 (push) Has been cancelled
build / Build for freebsd_arm (push) Has been cancelled
build / Build for linux_arm (push) Has been cancelled
build / Build for darwin_arm64 (push) Has been cancelled
build / Build for linux_arm64 (push) Has been cancelled
build / Build for windows_arm64 (push) Has been cancelled
build / Build Docker image for linux_386 (push) Has been cancelled
build / Build Docker image for linux_amd64 (push) Has been cancelled
build / Build Docker image for linux_arm (push) Has been cancelled
build / Build Docker image for linux_arm64 (push) Has been cancelled
build / Build e2etest for linux_386 (push) Has been cancelled
build / Build e2etest for windows_386 (push) Has been cancelled
build / Build e2etest for darwin_amd64 (push) Has been cancelled
build / Build e2etest for linux_amd64 (push) Has been cancelled
build / Build e2etest for windows_amd64 (push) Has been cancelled
build / Build e2etest for linux_arm (push) Has been cancelled
build / Build e2etest for darwin_arm64 (push) Has been cancelled
build / Build e2etest for linux_arm64 (push) Has been cancelled
build / Run e2e test for linux_386 (push) Has been cancelled
build / Run e2e test for windows_386 (push) Has been cancelled
build / Run e2e test for darwin_amd64 (push) Has been cancelled
build / Run e2e test for linux_amd64 (push) Has been cancelled
build / Run e2e test for windows_amd64 (push) Has been cancelled
build / Run e2e test for linux_arm (push) Has been cancelled
build / Run e2e test for linux_arm64 (push) Has been cancelled
build / Run terraform-exec test for linux amd64 (push) Has been cancelled
2025-10-31 09:54:11 +01:00
Liam Cervante
411f18e6ac
ephemerals: allow root ephemeral outputs in stacks and test (#37813)
* ephemerals: allow root ephemeral outputs in stacks and test

* remember to set new opt for apply stage
2025-10-28 09:29:44 +01:00
Liam Cervante
1e414491c7
evaluate: return diagnostics instead of unknown for uninitialised locals and resources (#37663)
* evaluate: return diagnostics instead of unknown for uninitialised locals and resources

* changelog

* also input variables
2025-09-24 16:27:43 +02:00
Liam Cervante
551ba2e525
Implement controlling destroy functionality within Terraform Test (#37359)
* Add ability to parse backend blocks present in a test file's run blocks, validate configuration (#36541)

* Add ability to parse backend blocks from a run block

* Add validation to avoid multiple backend blocks across run blocks that use the same internal state file. Update tests.

* Add validation to avoid multiple backend blocks within a single run block. Update tests.

* Remove use of quotes in diagnostic messages

* Add validation to avoid backend blocks being used in plan run blocks. Update tests.

* Correct local backend blocks in new test fixtures

* Add test to show that different test files can use same backend block for same state key.

* Add validation to enforce state-storage backend types are used

* Remove TODO comment

We only need to consider one file at a time when checking if a state_key already has a backend associated with it; parallelism in `terraform test` is scoped down to individual files.

* Add validation to assert that the backend block must be in the first apply command for an internal state

* Consolidate backend block validation inside a single if statement

* Add initial version of validation that ensures a backend isn't re-used within a file

* Explicitly set the state_key at the point of parsing the config

TODO: What should be done with method (moduletest.Run).GetStateKey?

* Update test fixture now that reusing backend configs has been made invalid

* Add automated test showing validation of reused configuration blocks

* Skip test due to flakiness, minor change to test config naming

* Update test so it tolerates non-deterministic order run blocks are evaluated in

* Remove unnecessary value assignment to r.StateKey

* Replace use of GetStateKey() with accessing the state key that's now set during test config parsing

* Fix bug so that run blocks using child modules get the correct state key set at parsing time

* Update acceptance test to also cover scenario where root and child module state keys are in use

* Update test name

* Add newline to regex

* Ensure consistent place where repeat backend error is raised from

* Write leftover test state(s) to file (#36614)

* Add additional validation that the backend used in a run is a supported type (#36648)

* Prevent test run when leftover state data is present (#36685)

* `test`: Set the initial state for a state files from a backend, allow the run that defines a backend to write state to the backend (#36646)

* Allow use of backend block to set initial state for a state key

* Note about alternative place to keep 'backend factories'

* Allow the run block defining the backend to write state to it

* Fix rebase

* Change to accessing backend init functions via ContextOpts

* Add tests demonstrating how runs containing backend blocks use and update persisted state

* Fix test fixture

* Address test failure due to trouble opening the state file

This problem doesn't happen on MacOS, so I assume is due to the Linux environment of GitHub runners.

* Fix issue with paths properly

I hope

* Fix defect in test assertion

* Pivot back to approach introduced in 4afc3d7

* Let failing tests write to persistent state, add test case covering that.

I split the acceptance tests into happy/unhappy paths for this, which required some of the helper functions' declarations to be raised up to package-level.

* Change how we update internal state files, so that information about the associated backend is never lost

* Fix UpdateStateFile

* Ensure that the states map set by TestStateTransformer associates a backend with the correct run.

* Misc spelling fixes in comments and a log

* Replace state get/set functions with existing helpers (#36747)

* Replace state get/set functions with existing helpers

* Compare to string representation of state

* Compare to string representation of state

* Terraform Test: Allow skipping cleanup of entire test file or individual run blocks (#36729)

* Add validation to enforce skip_cleanup=false cannot be used with backend blocks (#36857)

* Integrate use of backend blocks in tests with skip_cleanup feature (#36848)

* Fix nil pointer error, update test to not be table-driven

* Make using a backend block implicitly set skip_cleanup to true

* Stop state artefacts being created when a backend is in use and no cleanup errors have occurred

* Return diagnostics so calling code knows if cleanup experienced issues or not

* Update tests to show that when cleanup fails a state artefact is created

* Add comment about why diag not returned

* Bug fix - actually pull in the state from the state manager!

* Split and simplify (?) tests to show the backend block can create and/or reuse prior state

* Update test to use new fixtures, assert about state artefact. Fix nil pointer

* Update test fixture in use, add guardrail for flakiness of forced error during cleanup

* Refactor so resource ID set in only one place

* Add documentation for using a `backend` block during `test` (#36832)

* Add backend as a documented block in a run block

* Add documentation about backend blocks in run blocks.

* Make the relationship between backends and state keys more clear, other improvements

* More test documentation (#36838)

* Terraform Test: cleanup command (#36847)

* Allow cleanup of states that depend on prior runs outputs (#36902)

* terraform test: refactor graph edge calculation

* create fake run block nodes during cleanup operation

* tidy up TODOs

* fix tests

* remove old changes

* Update internal/moduletest/graph/node_state_cleanup.go

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

* Improve diagnostics around skip_cleanup conflicts (#37385)

* Improve diagnostics around skip_cleanup conflicts

* remove unused dynamic node

* terraform test: refactor manifest file for simplicity (#37412)

* test: refactor apply and plan functions so no run block is needed

* terraform test: write and load state manifest files

* Terraform Test: Allow skipping cleanup of entire test file or individual run blocks (#36729)

* terraform test: add support for skip_cleanup attr

* terraform test: add cleanup command

* terraform test: add backend blocks

* pause

* fix tests

* remove commented code

* terraform test: make controlling destroy functionality experimental (#37419)

* address comments

* Update internal/moduletest/graph/node_state_cleanup.go

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

---------

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

* add experimental changelog entries

---------

Co-authored-by: Sarah French <15078782+SarahFrench@users.noreply.github.com>
Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>
Co-authored-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
2025-09-10 17:22:20 +02:00
Samsondeen
af8cc7e315
test: create all edges to leaf cleanup nodes (#37564) 2025-09-09 11:20:56 +02:00
Liam Cervante
f931bc4e0e
test: don't panic when resolving references that haven't been evaluated (#37484) 2025-08-26 09:20:37 +02:00
Ricard Bejarano
4ac49bad2b
terraform test: fix regression when running with no tests (#37475) (#37477)
* terraform test: fix regression when running with no tests (#37475)

* added changelog entry

* move changelog entry from v1.14 to v1.13

* Return moduletest.Error instead of suite.Status if test operation is cancelled

* Add "terraform test" test with no tests

Yes, that's right. It's OK if you need to read it again.
2025-08-26 08:37:14 +02:00
Liam Cervante
dec0edfd5a
terraform test: enable deferrals in Terraform Test with the specified flag (#37370) 2025-07-30 11:03:41 +02:00
Liam Cervante
84c2e2f9e5
terraform test: override prevent_destroy meta attribute (#37364) 2025-07-25 13:54:56 +02:00
Liam Cervante
0a7701f19a
terraform test: refactor graph edge calculation (#37357)
* terraform test: refactor graph edge calculation

* remove unused attribute
2025-07-23 16:09:45 +02:00
Samsondeen
a1332299a5
Test run Parallelism of 1 should not result in deadlock (#37292) 2025-07-07 09:44:32 +02:00
Liam Cervante
777a916435
terraform test: move providers into the graph (#37216)
* terraform test: move providers into the graph

* consistency checks

* remove flaky cycle test

* address comments

* Update internal/moduletest/graph/node_test_run.go

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

* go fmt

---------

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>
2025-06-06 16:27:34 +02:00
Liam Cervante
53afa2cd2f
terraform test: move variable evaluation into the terraform test graph (#37205)
* terraform test: move variable evaluation into the terraform test graph

* make copyrightfix
2025-06-06 10:11:35 +02:00
Liam Cervante
063b7cf62b
terraform test: check specific dependencies before skipping run blocks (#37204)
* terraform test: check specific dependencies before skipping run blocks

* fix data race

* complete comment
2025-06-05 10:44:04 +00:00
Liam Cervante
757efaed9a
terraform test: automatically create edges based on references (#37200)
* terraform test: automatically create edges based on references

* address comments

* remove unused function
2025-06-03 14:33:43 +02:00
Liam Cervante
f80762d3d5
terraform test: add variable definitions to test files (#37195)
* terraform test: add variable definitions to test files

Currently, `terraform test` attempts to work out the type of any external variables by delaying evaluation until each run block executes so it can use the definitions within the run blocks's module. This means that the values of variables can technically change between run blocks which isn't ideal.

This commit is the first in a chain which will move the evaluation of variables into the terraform test graph. We need to give the users the option of specifying the type for external variables within the file as these variables are now going to be assessed outside of the context of a run block. To do this, we introduce the optional variable blocks that are added by this commit.

* update comment
2025-06-03 07:47:12 +00:00
Liam Cervante
7fadbe34de
write-only attributes: internal providers should set write-only attributes to null (#36824)
* write-only attributes: internal providers should set write-only attributes to null

* add changelog

* fix copywrite headers
2025-04-02 15:58:42 +02:00
Liam Cervante
aaf617d6d7
Add test case to ensure no regression of already fixed crash (#36583) 2025-03-05 11:24:53 +01:00
Samsondeen
3f4ed7e019
Ensure that all states are cleaned up (#36616) 2025-03-04 10:49:39 +01:00
Samsondeen
1bd312f155
Produce detailed diagnostic objects when test run assertions fail (#36522) 2025-03-03 15:46:04 +01:00
Samsondeen
018110c012
No state to cleaup when it is empty (#36526) 2025-02-18 19:33:41 +01:00
Samsondeen
2e91113224
Terraform test: Consolidate test execution procedure (#36459) 2025-02-11 14:48:48 +01:00
Samsondeen
4161e88391
Continue test execution after an expected failure (#36447) 2025-02-10 12:34:17 +01:00
Samsondeen
7f29df96a0
Allow terraform init when only test files are present in directory (#36429) 2025-02-06 09:20:09 +01:00
Samsondeen
2f0f537e69
Terraform test: Execute eligible test runs in parallel (#36300) 2025-02-05 15:18:38 +01:00
Sarah French
6b81f7184c
Change JUnit terraform test output to include test failure details inside <failure> elements, use the error message as the message attribute (#36316)
* Add details to `<failure>` element describing which assertion failed

* Remove unused diagnostic string

* Set `message` attribute of `<failure>` element to failed assertion's error message

* Make `<failure>` contain diagnostic's message, refactor how `message` attribute is set

* Ensure that system-err is only added when needed

* Update test fixtures

* Make diags usage clearer, ensure all test failure diags in "failure" element

* Refactor how "skipped" element value is set

* Fix failing test Test_TestJUnitXMLFile_Save
2025-01-22 16:42:04 +00:00
Kévin Andrieux
258f91ab0c
feat: add state_key for test run blocks (#36185)
* feat: add state_alias for test run blocks

* fix: move `state_alias` to run block + rename to `state_key`

* docs: add state_key changelog entry

* docs: add state_key in run block documentation

* Revert "docs: add state_key in run block documentation"

This reverts commit ccccf62a76.

* Revert "docs: add state_key changelog entry"

This reverts commit 86e2ad8dc3.
2025-01-16 10:34:47 +01:00
Liam Cervante
408f323efa
test: also allow mock_data and mock_resource blocks to generate data during planning (#36317) 2025-01-15 08:19:05 +01:00
Sarah French
ab6e4f2299
Refactor JUnit XML output of terraform test into a new junit package (#36304)
* Refactor JUnit XML output to use new concept of an Artifact

* Move JUnit-related code into new `artifact` package

* Refactor Artifact's Save method to return diagnostics, update comments

Previously TestJUnitXMLFile implemented the View interface, which cannot return errors. Now it's not a View any more we can simplify things.

* Make junitXMLTestReport output deterministic by iterating over a slice instead of a map, add test

* Provide sources to junitXMLTestReport, allowing complete error messages in the XML

We need to ensure that artifact.NewTestJUnitXMLFile is called once the config Loader is available as a non-nil pointer

* Whitespace

* Add some test coverage for JUnit XML output for `terraform test`

* Refactor how file is saved, add tests

* Move XML structs definitions outside of `junitXMLTestReport`

* Fix nil pointer bug

* Add missing file headers

* Refactor comparison of byte slices

* Rename package to `junit`, rename structs to match

* Add a test showing JUnit output when a test is skipped by the user
2025-01-13 13:25:58 +00:00
Samsondeen
aec7c3cc89
terraform test: allow computed/mocked values override during planning (#36227) 2025-01-08 12:39:03 +01:00
Daniel Schmidt
725add6a1a
test: pass in variables during apply
ephemeral variables need to be re-supplied
2024-10-16 16:30:31 +02:00
MicahKimel
3258744166
Remove invalid warning during cleanup phase (#35172)
* stop invalid warning during cleanup phase

* stop invalid warning during cleanup phase

* invalid warning during cleanup phase

* remove unwanted comment

* update GetVariables parameter for including warnings

* invalid warning during cleanup phase test case

* update invalid warnings in cleanup test case to throw a warning for the validation variable before cleanup phase

* remove unwanted warnings
2024-05-23 10:32:39 +02:00
Liam Cervante
448775102c
terraform test: Push evaluation of variables to as late as possible (#35014)
* terraform test: Push evaluation of variables to as late as possible

* Update internal/moduletest/hcl/variable_cache.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* address comments

---------

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2024-04-23 13:10:41 +02:00
Liam Cervante
6963c54bec
terraform test: don't remove sensitive marks from inputs (#35021) 2024-04-18 18:58:19 +02:00
Liam Cervante
c6ff573180
Include provider functions in scope used to evaluate test assertions (#34825) 2024-03-13 13:26:12 +01:00
Daniel Schmidt
0529299cc3
run terraform fmt on test 2024-02-23 13:50:46 +01:00
Daniel Schmidt
7ae7a203d8
test: allow using global variables in suite-level variable definitions
Closes #34534
2024-02-20 16:40:30 +01:00
Liam Cervante
9658f9df6b
mocking overrides: default to concrete empty object when values are missing (#34563) 2024-01-24 12:39:58 +01:00
Liam Cervante
430970c02b
terraform test: Fix crash when file level variables reference variables. (#34531)
* terraform test: Fix crash when referencing variables within the file level variable block

* also allow functions within variables blocks

* add tests
2024-01-22 20:00:22 +01:00
Liam Cervante
7e18b1183d
Add test verifying issue #34476 has been fixed (#34478) 2024-01-05 17:05:17 +01:00
Liam Cervante
5cbf7c5f96
Add docs for automatic var files in test directories (#34349) 2023-12-06 08:10:45 +01:00
Kubo
c98e355ca1
terraform test: Collect variables from default var file within testing directory (#34341)
* Add logic to collect variables for terrafrom test

* Add tests for test variable collection

* Update the test variable collection implementation

* Update internal/backend/local/test.go

Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>

* Update internal/backend/local/test.go

Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>

* Move test variables into var file

* resolve diff from cross-branch switch

* go fmt

---------

Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2023-12-04 08:15:56 +01:00
Liam Cervante
9ea1aa0a86
terraform test: skip destroy step for empty run blocks (#34331) 2023-11-30 16:38:23 +01:00
Liam Cervante
6670ab43f7
terraform test: rearrange the order of destroy operations (#34293) 2023-11-29 16:37:52 +01:00
Liam Cervante
dedb296773
terraform test: connect mock behaviour to test framework (#34205)
* connect mock behaviour to test framework

* fix calling unconfigured providers
2023-11-14 08:50:37 +01:00
Liam Cervante
57edb9c248
testing framework: add warnings for override blocks with invalid targets (#34181)
* testing framework: add warnings for override blocks with invalid targets

* pre-add the override sources for upcoming features

* address comments
2023-11-13 10:36:06 +01:00
Liam Cervante
b9f6b23ba3
testing framework: add support for functions in variables and providers (#34204) 2023-11-13 09:25:32 +01:00
Liam Cervante
ad77877136
terraform test: remove marks before passing variables as inputs to a plan (#34190)
* remove marks before passing variables as inputs to a plan

* fix doc comments
2023-11-08 09:34:04 +01:00