AT002

package
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2023 License: MPL-2.0 Imports: 5 Imported by: 3

README

AT002

The AT002 analyzer reports where the string _import or _Import is used in an acceptance test function name, which generally means there is an extraneous acceptance test. ImportState testing should be included as a TestStep with each applicable acceptance test, rather than a separate test that only verifies import of a single test configuration.

Flagged Code

func TestAccExampleThing_basic(t *testing.T) { // not flagged!
    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"),
                ),
            },
        },
    })
}

func TestAccExampleThing_importBasic(t *testing.T) { // flagged!
    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"),
                ),
            },
            {
                ResourceName:      "example_thing.test",
                ImportState:       true,
                ImportStateVerify: true,
            },
        },
    })
}

Passing Code

func TestAccExampleThing_basic(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"),
                ),
            },
            {
                ResourceName:      "example_thing.test",
                ImportState:       true,
                ImportStateVerify: true,
            },
        },
    })
}

Ignoring Reports

Singular reports can be ignored by adding the a //lintignore:AT002 Go code comment at the end of the offending line or on the line immediately proceding, e.g.

//lintignore:AT002
func TestAccExampleThing_importBasic(t *testing.T) {
    // ...
}

Documentation

Overview

Package AT002 defines an Analyzer that checks for acceptance test names including the word import

Index

Constants

View Source
const Doc = `` /* 410-byte string literal not displayed */

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: analyzerName,
	Doc:  Doc,
	Requires: []*analysis.Analyzer{
		testaccfuncdecl.Analyzer,
		commentignore.Analyzer,
	},
	Run: run,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL