Repository navigation
add AZT008: acceptance tests must be in a file named after the resource's file - #73
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A new rule, AZT008, that reports acceptance tests sitting in a file not named after the file declaring the resource or data source they test.
Why: a resource's tests are found by file name. When
lb_probe_resource.gois tested fromloadbalancer_probe_resource_test.go, nobody reading the resource finds its tests, and anything that pairs the two by name misses them. Run against azurerm it reports 17 of 1,908 acceptance test files. One is a real bug: a test named for the Linux scale set, in the scale set's file, that tests the Linux virtual machine instead, duplicating a test the virtual machine already has.Tests in a file named for something else. The rule takes what each test builds its test data for, finds the file that declares it, and expects the test file to carry that file's name. One report per test file, on the first test, with a count of the rest.
A test that drifted into another resource's file. The same check catches a single test that builds its data for the wrong thing.
// thing_resource_test.go func TestAccThing_probe(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + data := acceptance.BuildTestData(t, "azurerm_thing", "test")Splitting one resource's tests across files. By default a part between the declaring file's name and
_test.gois accepted, solb_probe_resource_identity_gen_test.gopasses. Thesuffixoption turns that off and requires exactlylb_probe_resource_test.go.What it reports in azurerm. Every report was checked against the files, and a separate check that ignores which resource a test is for found no test file the rule missed.
loadbalancer_file for anlb_resource_resource, as inkubernetes_cluster_network_resource_test.go_resourcemissing from the name, as innetapp_backup_vault_test.goThings that are fine as they are.
suffix: false, generated identity tests, list tests and state migration tests count as parts and are reported as well: 414 files in azurerm, so that setting does not suit azurerm today.The rule only reports.