Skip to content

Commit

Permalink
fix for etcd-io#19066 Print warnings when deprecated options are conf…
Browse files Browse the repository at this point in the history
…igured in config file

Signed-off-by: mansoora <[email protected]>
  • Loading branch information
mansoor17syed committed Jan 10, 2025
1 parent 52ca617 commit 5751838
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.",
},
},
{
Expand All @@ -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.",
},
},
}
Expand All @@ -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)
}
}
})
Expand Down

0 comments on commit 5751838

Please sign in to comment.