Skip to content

Commit

Permalink
Merge pull request kubernetes#125723 from p0lyn0mial/upstream-refacto…
Browse files Browse the repository at this point in the history
…r-watch-list-kcm-units

kube-controller-manager: refactor watchlist unit tests
  • Loading branch information
k8s-ci-robot committed Jun 26, 2024
2 parents a3a4f96 + cc7063e commit 3084c15
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions cmd/kube-controller-manager/app/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,35 +1320,26 @@ func TestControllerManagerAliases(t *testing.T) {
}

func TestWatchListClientFlagUsage(t *testing.T) {
assertWatchListClientFeatureDefaultValue(t)

fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s, _ := NewKubeControllerManagerOptions()
for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
fs.AddFlagSet(f)
}

fgFlagName := "feature-gates"
fg := fs.Lookup(fgFlagName)
if fg == nil {
t.Fatalf("didn't find %q flag", fgFlagName)
}

expectedWatchListClientString := "WatchListClient=true|false (BETA - default=false)"
if !strings.Contains(fg.Usage, expectedWatchListClientString) {
t.Fatalf("%q flag doesn't contain the expected usage for %v feature gate.\nExpected = %v\nUsage = %v", fgFlagName, clientgofeaturegate.WatchListClient, expectedWatchListClientString, fg.Usage)
}
assertWatchListClientFeatureDefaultValue(t)
assertWatchListCommandLineDefaultValue(t, fs)
}

func TestWatchListClientFlagChange(t *testing.T) {
assertWatchListClientFeatureDefaultValue(t)

fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s, _ := NewKubeControllerManagerOptions()
for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
fs.AddFlagSet(f)
}

assertWatchListClientFeatureDefaultValue(t)
assertWatchListCommandLineDefaultValue(t, fs)

args := []string{fmt.Sprintf("--feature-gates=%v=true", clientgofeaturegate.WatchListClient)}
if err := fs.Parse(args); err != nil {
t.Fatal(err)
Expand All @@ -1367,6 +1358,19 @@ func assertWatchListClientFeatureDefaultValue(t *testing.T) {
}
}

func assertWatchListCommandLineDefaultValue(t *testing.T, fs *pflag.FlagSet) {
fgFlagName := "feature-gates"
fg := fs.Lookup(fgFlagName)
if fg == nil {
t.Fatalf("didn't find %q flag", fgFlagName)
}

expectedWatchListClientString := "WatchListClient=true|false (BETA - default=false)"
if !strings.Contains(fg.Usage, expectedWatchListClientString) {
t.Fatalf("%q flag doesn't contain the expected usage for %v feature gate.\nExpected = %v\nUsage = %v", fgFlagName, clientgofeaturegate.WatchListClient, expectedWatchListClientString, fg.Usage)
}
}

type sortedGCIgnoredResources []garbagecollectorconfig.GroupResource

func (r sortedGCIgnoredResources) Len() int {
Expand Down

0 comments on commit 3084c15

Please sign in to comment.