Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Extra Check: TestCase Missing ErrorCheck #226

Closed
bflad opened this issue Mar 18, 2021 · 0 comments · Fixed by #227
Closed

New Extra Check: TestCase Missing ErrorCheck #226

bflad opened this issue Mar 18, 2021 · 0 comments · Fixed by #227
Assignees
Labels
ast AST Handling check/acctest Acceptance Testing Check new-check New Lint Check
Milestone

Comments

@bflad
Copy link
Owner

bflad commented Mar 18, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Terraform Plugin SDK v2.3.0 added helper/resource.TestCase.ErrorCheck, which is described as:

 	// ErrorCheck allows providers the option to handle errors such as skipping
	// tests based on certain errors.

Certain providers may wish to always require this functionality in testing to skip acceptance test errors for known environmental issues (such as running in environments with known limited functionality).

New Check

  • XAT001

Flagged Provider Code

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"),
                ),
            },
        },
    })
}

Passing Provider Code

func TestAccExampleThing_Attr1(t *testing.T) {
    resource.ParallelTest(t, resource.TestCase{
        PreCheck:  func() { testAccPreCheck(t) },
        Providers: testAccProviders,
        ErrorCheck: testAccErrorCheck,
        CheckDestroy: testAccCheckExampleThingDestroy,
        Steps: []resource.TestStep{
            {
                Config: testAccExampleThingConfig(),
                Check: resource.ComposeTestCheckFunc(
                    resource.TestCheckResourceAttrSet("example_thing.test", "attr1"),
                ),
            },
        },
    })
}

References

@bflad bflad added ast AST Handling new-check New Lint Check check/acctest Acceptance Testing Check labels Mar 18, 2021
@bflad bflad added this to the v0.23.0 milestone Mar 18, 2021
@bflad bflad self-assigned this Mar 18, 2021
bflad added a commit that referenced this issue Mar 18, 2021
* deps: Bump github.com/hashicorp/terraform-plugin-sdk/[email protected]

Updated via:

```
go get github.com/hashicorp/terraform-plugin-sdk/[email protected]
go mod tidy
go mod vendor
```

* deps: Bump github.com/hashicorp/terraform-plugin-sdk@v1-maint

To prevent `go-getter` errors.

Updated via:

```
go get github.com/hashicorp/terraform-plugin-sdk@v1-maint
go mod tidy
go mod vendor
```

* New Extra Check: XAT001: check for TestCase missing ErrorCheck

Reference: #226
Mikechoi78 added a commit to Mikechoi78/tfproviderlint that referenced this issue May 23, 2022
* deps: Bump github.com/hashicorp/terraform-plugin-sdk/[email protected]

Updated via:

```
go get github.com/hashicorp/terraform-plugin-sdk/[email protected]
go mod tidy
go mod vendor
```

* deps: Bump github.com/hashicorp/terraform-plugin-sdk@v1-maint

To prevent `go-getter` errors.

Updated via:

```
go get github.com/hashicorp/terraform-plugin-sdk@v1-maint
go mod tidy
go mod vendor
```

* New Extra Check: XAT001: check for TestCase missing ErrorCheck

Reference: bflad/tfproviderlint#226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast AST Handling check/acctest Acceptance Testing Check new-check New Lint Check
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant