$npx -y skills add hashicorp/agent-skills --skill run-acceptance-testsGuide for running acceptance tests for a Terraform provider. Use this when asked to run an acceptance test or to run a test with the prefix TestAcc.
| 1 | An acceptance test is a Go test function with the prefix `TestAcc`. |
| 2 | |
| 3 | To run a focussed acceptance test named `TestAccFeatureHappyPath`: |
| 4 | |
| 5 | 1. Run `go test -run=TestAccFeatureHappyPath` with the following environment |
| 6 | variables: |
| 7 | - `TF_ACC=1` |
| 8 | |
| 9 | Default to non-verbose test output. |
| 10 | 1. The acceptance tests may require additional environment variables for |
| 11 | specific providers. If the test output indicates missing environment |
| 12 | variables, then suggest how to set up these environment variables securely. |
| 13 | |
| 14 | To diagnose a failing acceptance test, use these options, in order. These |
| 15 | options are cumulative: each option includes all the options above it. |
| 16 | |
| 17 | 1. Run the test again. Use the `-count=1` option to ensure that `go test` does |
| 18 | not use a cached result. |
| 19 | 1. Offer verbose `go test` output. Use the `-v` option. |
| 20 | 1. Offer debug-level logging. Enable debug-level logging with the environment |
| 21 | variable `TF_LOG=debug`. |
| 22 | 1. Offer to persist the acceptance test's Terraform workspace. Enable |
| 23 | persistance with the environment variable `TF_ACC_WORKING_DIR_PERSIST=1`. |
| 24 | |
| 25 | A passing acceptance test may be a false negative. To "flip" a passing |
| 26 | acceptance test named `TestAccFeatureHappyPath`: |
| 27 | |
| 28 | 1. Edit the value of one of the TestCheckFuncs in one of the TestSteps in the |
| 29 | TestCase. |
| 30 | 1. Run the acceptance test. Expect the test to fail. |
| 31 | 1. If the test fails, then undo the edit and report a successful flip. Else, |
| 32 | keep the edit and report an unsuccessful flip. |