| name | acctest-mocks |
| description | Create or update mock data for Terraform provider acceptance tests using recorded GraphQL calls under tmp_recorded and replay fixtures under test_data. Use when Codex needs to generate or refresh mocked API data for acctests instead of real Cato API calls, inspect GraphQL operationName traffic, build accmock config.yaml files, or create resource mock YAML files for TF_ACC_MOCK=1 runs. |
Terraform Acctest Mocks
Use this skill to create or update mock data for tests under ./internal/acctests/. Mock fixtures live under ./test_data/<TestFunctionName>/ and are consumed when running tests with TF_ACC_MOCK=1.
Prerequisites
- Ensure
CATO_ACCOUNT_ID is set.
- Ask the user to confirm the account ID is correct. Stop if the user does not confirm.
Identify The Test
- Determine the exact acceptance test function. Tests are in
./internal/acctests/<test-directory>/ and functions start with TestAcc.
- If the prompt does not specify the exact test, ask the user before continuing.
- Record:
- Test function name, such as
TestAccStaticHost.
- Test directory, such as
static_host.
- Use the test function name as the mock fixture name under
./test_data/.
Record Real API Traffic
- Delete
./tmp_recorded/ before recording so only this run's traffic is present. This is an intentional cleanup step for generated recording output.
- Run the focused real-API test and require exit code 0:
TF_ACC=1 TF_ACC_MOCK='' go test -timeout 120s -tags acctest -count=1 -parallel=1 -p 1 -run <TEST-NAME> ./internal/acctests/<TEST-DIRECTORY>/ -v
- Inspect
./tmp_recorded/<TEST-NAME>/. Recorded filenames use <time>_<operationName>.txt, for example 20260519_110848.065_entityLookup.txt.
- Extract every distinct
operationName from those filenames.
- For each recorded file, inspect the line that starts with
{"operationName":; this line is the GraphQL request JSON body.
- Use the last line of each recorded file as the real API response to adapt into the mock YAML body.
Classify Operations
For each GraphQL request, determine:
- Operation type:
CREATE, READ, UPDATE, DELETE, or NO_CONTENT.
- Target resource, such as
networkRangeList or staticHost.
- Resource name or ID variable path:
- For
CREATE, find the path to the name, such as variables.addStaticHostInput.name.
- For
READ, UPDATE, and DELETE, find the path to the ID, such as variables.hostId.
- Whether the operation is static. Static operations query existing shared resources and do not mutate the resource under test.
To identify static resources, read ./internal/acctests/acc/common.go and scan for GetXxxx(t *testing.T) helper functions. Resources returned by those helpers should be treated as static fixtures.
Special cases:
entityLookup: classify as READ; define subtypes from variables.type.
policyPrivateAccessDiscardRevision: classify as NO_CONTENT.
Create Fixture Layout
- Create
./test_data/<TEST-NAME>/.
- Create one resource-type directory per mocked resource, such as
./test_data/TestAccStaticHost/staticHost/.
- Create one resource-name directory per resource instance, such as
./test_data/TestAccStaticHost/staticHost/acctest_static_host_1/.
- Keep names deterministic. If the real response contains randomized suffixes, remove only the random part, for example convert
acctest_static_host_fwcowd6p4h to acctest_static_host.
Create config.yaml
- Inspect
type config struct in ./internal/accmock/mockserver.go.
- Inspect an existing fixture such as
./test_data/TestAccAppConnector/config.yaml.
- Create or update
./test_data/<TEST-NAME>/config.yaml to map operations to the resource fixtures needed by this test.
- Match existing config style and field names exactly; do not invent schema fields.
Create Mock YAML Files
- In each resource-name directory, create action files named
<sequence>_<action>.yaml.
- Use a three-digit sequence number such as
000.
- Use action names:
create
read
update
zap for delete cleanup
- For create files, define
ResourceID. Use a deterministic mocked database ID such as "1000" unless an existing fixture pattern requires otherwise.
- Every action file must include
GraphQL.StatusCode, GraphQL.Delay, and GraphQL.Body.
- Use the recorded API response as the basis for
GraphQL.Body, preserving response shape while normalizing randomized names.
- Ensure IDs returned inside
GraphQL.Body match the ResourceID used by the create fixture.
Example shape:
ResourceID: "1000"
GraphQL:
StatusCode: 200
Delay: 0ms
Body: { "data": { "mock": { "id": "1000", "name": "acctest_static_host_1" } } }
Test Mock Replay
Run the same focused test with mock replay enabled:
TF_ACC=1 TF_ACC_MOCK='1' go test -timeout 120s -tags acctest -count=1 -parallel=1 -p 1 -run <TEST-NAME> ./internal/acctests/<TEST-DIRECTORY>/ -v
The test must pass. If it fails, compare the failure against ./internal/accmock/mockserver.go, the generated config.yaml, and the recorded request/response files, then adjust the fixture mappings or bodies.
Restrictions
- Do not commit to git.
- Do not remove unrelated files under
./test_data/ or local scratch output.
- Do not edit provider source or acceptance test source unless the user explicitly asks for that separate change.