diff --git a/server/etcdmain/config_test.go b/server/etcdmain/config_test.go index ae7f91bf60b..b9058d33739 100644 --- a/server/etcdmain/config_test.go +++ b/server/etcdmain/config_test.go @@ -667,12 +667,12 @@ func TestConfigFileDeprecatedOptions(t *testing.T) { testCases := []struct { name string configFileYAML configStruct - expectedWarnings []string + expectedWarnings map[string]string }{ { name: "no deprecated options", configFileYAML: configStruct{}, - expectedWarnings: nil, + expectedWarnings: map[string]string{}, }, { name: "deprecated experimental options", @@ -681,10 +681,10 @@ func TestConfigFileDeprecatedOptions(t *testing.T) { ExperimentalCompactHashCheckTime: 2 * time.Minute, ExperimentalWarningUnaryRequestDuration: time.Second, }, - expectedWarnings: []string{ - "experimental-compact-hash-check-enabled is deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=CompactHashCheck=true' instead", - "experimental-compact-hash-check-time is deprecated in v3.6 and will be decommissioned in v3.7. Use --compact-hash-check-time instead", - "experimental-warning-unary-request-duration is deprecated, and will be decommissioned in v3.7. Use warning-unary-request-duration instead", + expectedWarnings: map[string]string{ + "experimental-compact-hash-check-enabled": "--experimental-compact-hash-check-enabled is deprecated in 3.6 and will be decommissioned in 3.7. Use '--feature-gates=CompactHashCheck=true' instead.", + "experimental-compact-hash-check-time": "--experimental-compact-hash-check-time is deprecated in 3.6 and will be decommissioned in 3.7. Use '--compact-hash-check-time' instead.", + "experimental-warning-unary-request-duration": "--experimental-warning-unary-request-duration is deprecated, and will be decommissioned in v3.7. Use --warning-unary-request-duration instead.", }, }, { @@ -693,9 +693,9 @@ func TestConfigFileDeprecatedOptions(t *testing.T) { SnapshotCount: 10000, MaxSnapFiles: 5, }, - expectedWarnings: []string{ - "snapshot-count is deprecated in v3.6 and will be decommissioned in v3.7", - "max-snapshots is deprecated in v3.6 and will be decommissioned in v3.7", + expectedWarnings: map[string]string{ + "snapshot-count": "--snapshot-count is deprecated in 3.6 and will be decommissioned in 3.7.", + "max-snapshots": "--max-snapshots is deprecated in 3.6 and will be decommissioned in 3.7.", }, }, } @@ -716,33 +716,24 @@ func TestConfigFileDeprecatedOptions(t *testing.T) { t.Fatal(err) } - // Check if the expected flags were marked as deprecated + // Check for unexpected warnings for flagName := range cfg.ec.FlagsExplicitlySet { if msg, ok := deprecatedFlags[flagName]; ok { - found := false - for _, expected := range tc.expectedWarnings { - if msg == expected { - found = true - break - } + expectedMsg, shouldWarn := tc.expectedWarnings[flagName] + if !shouldWarn { + t.Errorf("unexpected deprecated flag warning for %q", flagName) + continue } - if !found { - t.Errorf("unexpected deprecated flag warning for %q: %q", flagName, msg) + if msg != expectedMsg { + t.Errorf("warning message mismatch for %q:\ngot: %q\nwant: %q", flagName, msg, expectedMsg) } } } - // Check if all expected warnings were present - for _, expected := range tc.expectedWarnings { - found := false - for flagName := range cfg.ec.FlagsExplicitlySet { - if msg, ok := deprecatedFlags[flagName]; ok && msg == expected { - found = true - break - } - } - if !found { - t.Errorf("missing expected warning: %q", expected) + // Check for missing warnings + for flagName, expectedMsg := range tc.expectedWarnings { + if msg, ok := deprecatedFlags[flagName]; !ok || msg != expectedMsg { + t.Errorf("missing or incorrect warning for %q:\ngot: %q\nwant: %q", flagName, msg, expectedMsg) } } })