Remove patchActual, does not appear to be necessary

also small rename and fix comment
pull/9452/head
Daniel Nephin 4 years ago
parent e6afd65236
commit 4411da5ddd

@ -34,37 +34,33 @@ import (
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
) )
type configTest struct { // testCase used to test different config loading and flag parsing scenarios.
desc string type testCase struct {
args []string desc string
pre func() args []string
json, jsontail []string pre func()
hcl, hcltail []string json []string
privatev4 func() ([]*net.IPAddr, error) hcl []string
publicv6 func() ([]*net.IPAddr, error) patch func(rt *RuntimeConfig) // expected
patch func(rt *RuntimeConfig) err string // expectedErr
patchActual func(rt *RuntimeConfig) warns []string // expectedWarnings
err string
warns []string hcltail, jsontail []string
hostname func() (string, error) privatev4 func() ([]*net.IPAddr, error)
publicv6 func() ([]*net.IPAddr, error)
hostname func() (string, error)
} }
// TestConfigFlagsAndEdgecases tests the command line flags and // TestConfigFlagsAndEdgecases tests the command line flags and
// edgecases for the config parsing. It provides a test structure which // edgecases for the config parsing. It provides a test structure which
// checks for warnings on deprecated fields and flags. These tests // checks for warnings on deprecated fields and flags. These tests
// should check one option at a time if possible and should use generic // should check one option at a time if possible
// values, e.g. 'a' or 1 instead of 'servicex' or 3306.
func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) { func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) {
if testing.Short() {
t.Skip("too slow for testing.Short")
}
dataDir := testutil.TempDir(t, "consul") dataDir := testutil.TempDir(t, "consul")
defaultEntMeta := structs.DefaultEnterpriseMeta() defaultEntMeta := structs.DefaultEnterpriseMeta()
tests := []configTest{ tests := []testCase{
// ------------------------------------------------------------ // ------------------------------------------------------------
// cmd line flags // cmd line flags
// //
@ -3940,17 +3936,6 @@ func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) {
} }
`, `,
}, },
patchActual: func(rt *RuntimeConfig) {
// Wipe the time tracking fields to make comparison easier.
for _, raw := range rt.ConfigEntryBootstrap {
if entry, ok := raw.(*structs.ServiceIntentionsConfigEntry); ok {
for _, src := range entry.Sources {
src.LegacyCreateTime = nil
src.LegacyUpdateTime = nil
}
}
}
},
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.DataDir = dataDir rt.DataDir = dataDir
rt.ConfigEntryBootstrap = []structs.ConfigEntry{ rt.ConfigEntryBootstrap = []structs.ConfigEntry{
@ -4028,17 +4013,6 @@ func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) {
} }
`, `,
}, },
patchActual: func(rt *RuntimeConfig) {
// Wipe the time tracking fields to make comparison easier.
for _, raw := range rt.ConfigEntryBootstrap {
if entry, ok := raw.(*structs.ServiceIntentionsConfigEntry); ok {
for _, src := range entry.Sources {
src.LegacyCreateTime = nil
src.LegacyUpdateTime = nil
}
}
}
},
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.DataDir = dataDir rt.DataDir = dataDir
rt.ConfigEntryBootstrap = []structs.ConfigEntry{ rt.ConfigEntryBootstrap = []structs.ConfigEntry{
@ -4863,11 +4837,12 @@ func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) {
testConfig(t, tests, dataDir) testConfig(t, tests, dataDir)
} }
func testConfig(t *testing.T, tests []configTest, dataDir string) { func testConfig(t *testing.T, tests []testCase, dataDir string) {
for _, tt := range tests { for _, tt := range tests {
for pass, format := range []string{"json", "hcl"} { for pass, format := range []string{"json", "hcl"} {
// clean data dir before every test // clean data dir before every test
cleanDir(dataDir) os.RemoveAll(dataDir)
os.MkdirAll(dataDir, 0755)
// when we test only flags then there are no JSON or HCL // when we test only flags then there are no JSON or HCL
// sources and we need to make only one pass over the // sources and we need to make only one pass over the
@ -4980,9 +4955,6 @@ func testConfig(t *testing.T, tests []configTest, dataDir string) {
require.Equal(t, actual.DataDir, actual.ACLTokens.DataDir) require.Equal(t, actual.DataDir, actual.ACLTokens.DataDir)
expected.ACLTokens.DataDir = actual.ACLTokens.DataDir expected.ACLTokens.DataDir = actual.ACLTokens.DataDir
if tt.patchActual != nil {
tt.patchActual(&actual)
}
assertDeepEqual(t, expected, actual, cmpopts.EquateEmpty()) assertDeepEqual(t, expected, actual, cmpopts.EquateEmpty())
}) })
} }
@ -6343,19 +6315,6 @@ func writeFile(path string, data []byte) {
} }
} }
func cleanDir(path string) {
root := path
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if path == root {
return nil
}
return os.RemoveAll(path)
})
if err != nil {
panic(err)
}
}
func randomString(n int) string { func randomString(n int) string {
s := "" s := ""
for ; n > 0; n-- { for ; n > 0; n-- {

@ -11,7 +11,7 @@ import (
func TestSegments(t *testing.T) { func TestSegments(t *testing.T) {
dataDir := testutil.TempDir(t, "consul") dataDir := testutil.TempDir(t, "consul")
tests := []configTest{ tests := []testCase{
{ {
desc: "segment name not in OSS", desc: "segment name not in OSS",
args: []string{ args: []string{

Loading…
Cancel
Save