--- name: review-tests description: "Review Terraform AWS Provider acceptance and unit test basics: required _basic and _disappears tests, TestAcc naming, TestCase essentials (PreCheck/ErrorCheck/ProtoV5ProviderFactories/CheckDestroy), random naming, ImportState steps, and regexache. Use when reviewing a PR that changes internal/service/**/*_test.go." --- # Review: Acceptance & Unit Tests Assume the `@maintainer` persona. Scope: per-resource acceptance test basics. Ephemeral resources, provider functions, and actions are out of scope. See `review-tests-helpers` for Exists/Destroy and data source/list/unit tests. Loaded from `review-pr`. ## Required tests for new resources - `TestAcc_basic` — full happy path, including an `ImportState` step, checking all attributes. - `TestAcc_disappears` — verifies the provider re-creates a resource that's gone out-of-band. Tag and identity tests are **generated** for resources with `@Tags` and identity annotations. Flag PRs that add hand-written `_tags*` or `_Identity_*` tests for new resources. ## Naming - Acceptance tests: `TestAcc_`. - Data source acceptance tests: `TestAccDataSource_`. - List resource acceptance tests: `TestAcc_List_`. - Unit tests: anything **without** the `TestAcc` prefix; flag any unit test that calls AWS. ## TestCase essentials Acceptance tests start with `ctx := acctest.Context(t)` and use `acctest.ParallelTest(ctx, t, resource.TestCase{...})`. The `TestCase` must set: - `PreCheck` calling `acctest.PreCheck(ctx, t)`, `acctest.PreCheckPartitionHasService(t, names.EndpointID)`, and the package's `testAccPreCheck(ctx, t)`. - `ErrorCheck: acctest.ErrorCheck(t, names.ServiceID)`. - `ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories`. - `CheckDestroy: testAccCheckDestroy(ctx, t)`. Flag missing or replaced versions of any of those. For tests expected to run more than ~5 minutes, add the long-running guard right after `acctest.Context(t)`: ```go if testing.Short() { t.Skip("skipping long-running test in short mode") } ``` ## Random naming Use `sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)`. Flag hard-coded names or bare `acctest.RandString(...)`. ## PreCheck pattern `testAccPreCheck` issues a single cheap List/Describe call and skips on partition/permission errors via `acctest.PreCheckSkipError(err)`. Flag PreChecks that make multiple API calls, return errors instead of calling `t.Skipf`/`t.Fatalf`, or skip `PreCheckSkipError`. ## ImportState step The `_basic` test's last step verifies import: ```go { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, } ``` `ImportStateVerifyIgnore` is for write-only fields the AWS API doesn't return (e.g., passwords, `apply_immediately`). Flag broad ignore lists used to paper over genuine drift. ## Disappears test - Framework: `acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tf.Resource, resourceName)`. - SDKv2: `acctest.CheckResourceDisappears(ctx, acctest.Provider, tf.Resource(), resourceName)`. ## Regex and ARN checks - Use `github.com/YakDriver/regexache`, not stdlib `regexp`. Flag any new test that imports `regexp`. - For ARN attributes use `acctest.MatchResourceAttrRegionalARN` / `CheckResourceAttrRegionalARN` (or global / alt-region variants). Flag manual ARN assembly via `fmt.Sprintf` with account ID or region.