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
  • Loading branch information
mansoor17syed committed Jan 10, 2025
1 parent 70b0e50 commit 247ab42
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"errors"
"flag"
"fmt"
"maps"
"net/url"
"os"
"reflect"
"sort"
"slices"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -656,40 +657,32 @@ func validateClusteringFlags(t *testing.T, cfg *config) {
}

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
configFileYAML embed.Config
expectedFlags map[string]struct{}
}{
{
name: "no deprecated options",
configFileYAML: configStruct{},
configFileYAML: embed.Config{},
expectedFlags: map[string]struct{}{},
},
{
name: "deprecated experimental options",
configFileYAML: configStruct{
configFileYAML: embed.Config{
ExperimentalCompactHashCheckEnabled: true,
ExperimentalCompactHashCheckTime: 2 * time.Minute,
ExperimentalWarningUnaryRequestDuration: time.Second,
},
expectedFlags: map[string]struct{}{
"experimental-compact-hash-check-enabled": {},
"experimental-compact-hash-check-time": {},
// experimental-warning-unary-request-duration is handled differently
},
},
{
name: "deprecated snapshot options",
configFileYAML: configStruct{
configFileYAML: embed.Config{
SnapshotCount: 10000,
MaxSnapFiles: 5,
},
Expand Down Expand Up @@ -729,8 +722,8 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
// Compare sets of flags
if !reflect.DeepEqual(foundFlags, tc.expectedFlags) {
t.Errorf("deprecated flags mismatch:\ngot: %v\nwant: %v",
mapToSortedSlice(foundFlags),
mapToSortedSlice(tc.expectedFlags))
slices.Sorted(maps.Keys(foundFlags)),
slices.Sorted(maps.Keys(tc.expectedFlags)))
}

// Special check for experimental-warning-unary-request-duration
Expand All @@ -742,13 +735,3 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
})
}
}

// Helper function to convert map keys to sorted slice for better error messages
func mapToSortedSlice(m map[string]struct{}) []string {
result := make([]string, 0, len(m))
for k := range m {
result = append(result, k)
}
sort.Strings(result)
return result
}

0 comments on commit 247ab42

Please sign in to comment.