Remove test boilerplate by adding build tag
Description
Relates to #1008 (closed)
I'm interested in feedback on this. Is this a good change, if contributors now have to be sure to add the // +build acceptance header to new tests, or should we instead keep our test-skipping logic as it is?
The goal of this PR is to remove the testAccCheck(t) and PreCheck boilerplate code from all tests.
I was able to do this by introducing an "acceptance" build tag.
The 4 commits are independent, so you can review them separately.
-
Run acceptance tests with acceptance build tag
- I added the
// +build acceptancebuild tag on all acceptance test files, but NOT unit test files. This allows us to run acceptance tests by specifyinggo test -tags acceptance, and keep the defaultgo testcommand only running unit tests, without the need to check the value ofTF_ACCin every test.
- I added the
-
Run tfproviderlint as a golangci-lint plugin
- I changed the way that we run tfproviderlint so that instead of running the binary, we run it as a plugin of golangci-lint. This was necessary because tfproviderlint does not allow you to specify build tags, so it was not linting acceptance tests anymore. Whereas, golangci-lint does let you specify build tags.
-
Allow linters to lint acceptance tests
- Runs linters with
--build-tags acceptanceso that acceptance tests are included in linting.
- Runs linters with
-
Remove skip-test checks and rely on build tags instead
- Deleted all uses of
testAccCheckandPreCheck. Now that acceptance tests are enabled using anacceptancebuild tag, we do not need to do these runtime checks.
- Deleted all uses of
PR Checklist Acknowledgement
-
I acknowledge that all of the following items are true, where applicable: - Resource attributes match 1:1 the names and structure of the API resource in the GitLab API documentation.
-
Examples are updated with:
- A *.tf file for the resource/s with at least one usage example
- A *.sh file for the resource/s with an import example (if applicable)
- New resources have at minimum a basic test with three steps:
- Create the resource
- Update the attributes
- Import the resource
- No new
//lintignorecomments were copied from existing code. (Linter rules are meant to be enforced on new code.)