diff --git a/server/etcdmain/config_test.go b/server/etcdmain/config_test.go index b834f3d33ea..ae7f91bf60b 100644 --- a/server/etcdmain/config_test.go +++ b/server/etcdmain/config_test.go @@ -653,3 +653,98 @@ func validateClusteringFlags(t *testing.T, cfg *config) { t.Errorf("advertise-client-urls = %v, want %v", cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls) } } + +func TestConfigFileDeprecatedOptions(t *testing.T) { + type configStruct struct { + SnapshotCount uint64 `json:"snapshot-count,omitempty"` + MaxSnapFiles uint `json:"max-snapshots,omitempty"` + V2Deprecation string `json:"v2-deprecation,omitempty"` + ExperimentalCompactHashCheckEnabled bool `json:"experimental-compact-hash-check-enabled,omitempty"` + ExperimentalCompactHashCheckTime time.Duration `json:"experimental-compact-hash-check-time,omitempty"` + ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"` + } + + testCases := []struct { + name string + configFileYAML configStruct + expectedWarnings []string + }{ + { + name: "no deprecated options", + configFileYAML: configStruct{}, + expectedWarnings: nil, + }, + { + name: "deprecated experimental options", + configFileYAML: configStruct{ + ExperimentalCompactHashCheckEnabled: true, + 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", + }, + }, + { + name: "deprecated snapshot options", + configFileYAML: configStruct{ + 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", + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + b, err := yaml.Marshal(&tc.configFileYAML) + if err != nil { + t.Fatal(err) + } + + tmpfile := mustCreateCfgFile(t, b) + defer os.Remove(tmpfile.Name()) + + cfg := newConfig() + err = cfg.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())}) + if err != nil { + t.Fatal(err) + } + + // Check if the expected flags were marked as deprecated + 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 + } + } + if !found { + t.Errorf("unexpected deprecated flag warning for %q: %q", flagName, msg) + } + } + } + + // 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) + } + } + }) + } +}