AT001¶
Acceptance testsStandard
check for TestCase missing CheckDestroy
The AT001 analyzer reports likely incorrect uses of TestCase
which do not define a CheckDestroy function. CheckDestroy is used to verify
that test infrastructure has been removed at the end of an acceptance test.
Options¶
Namespaced under the check ID on the command line, as -AT001.ignored-filename-prefixes=VALUE.
| Flag | Default | Effect |
|---|---|---|
ignored-filename-prefixes |
data_source_ |
Comma-separated list of file name prefixes to ignore |
ignored-filename-suffixes |
none | Comma-separated list of file name suffixes to ignore |
More information: https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy
Examples¶
Note
This analyzer does not differentiate between resource acceptance tests and data source acceptance tests. This is by design to ensure authors add the equivalent resource CheckDestroy function to data source testing, if available.
func TestAccExampleThing_Attr1(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccExampleThingConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("example_thing.test", "attr1"),
),
},
},
})
}
func testAccCheckExampleThingDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "example_thing" {
continue
}
/* Code to check API for existence of Example Thing */
}
return nil
}
func TestAccExampleThing_Attr1(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckExampleThingDestroy,
Steps: []resource.TestStep{
{
Config: testAccExampleThingConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("example_thing.test", "attr1"),
),
},
},
})
}
Ignoring reports¶
Singular reports can be ignored by adding a //lintignore:AT001 Go code comment at the end of the offending line or on the line immediately preceding, e.g.
func TestAccExampleThing_Attr1(t *testing.T) {
//lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccExampleThingConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("example_thing.test", "attr1"),
),
},
},
})
}
This page is generated from passes/AT001/README.md, which lives beside the analyzer.