config: make TestLoad_IntegrationWithFlags easier to work with

Replace the large table of tests with individual calls to run(). By using
runCase, failure messages will include the line number for the test case, as
well as a line number from the test functions.

Example:
=== FAIL: agent/config TestLoad_IntegrationWithFlags/failing_case (0.01s)
    runtime_test.go:4721: case: failing case
    runtime_test.go:4864: error "data_dir cannot be empty" does not contain "I expected this error"

Previous:
    runtime_test.go:4864: error "data_dir cannot be empty" does not contain "I expected this error"

Without the line number to the testCase data, debugging these tests is
difficult. It is impossible to jump directly to the test case, and
difficult to find the location because of many similarly named cases.
This commit is contained in:
Daniel Nephin 2020-12-21 19:00:36 -05:00
parent db53954a3f
commit e6badb3129
2 changed files with 3003 additions and 2992 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
package config
import (
"fmt"
"testing"
"github.com/hashicorp/consul/sdk/testutil"
@ -50,9 +51,10 @@ func TestSegments(t *testing.T) {
},
}
for _, tt := range tests {
for _, tc := range tests {
for _, format := range []string{"json", "hcl"} {
testConfig(t, tt, format, dataDir)
name := fmt.Sprintf("%v_%v", tc.desc, format)
t.Run(name, tc.run(format, dataDir))
}
}
}