kube-controller-manager: refactor watchlist unit tests
This commit is contained in:
		@@ -1320,35 +1320,26 @@ func TestControllerManagerAliases(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWatchListClientFlagUsage(t *testing.T) {
 | 
					func TestWatchListClientFlagUsage(t *testing.T) {
 | 
				
			||||||
	assertWatchListClientFeatureDefaultValue(t)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
						fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
				
			||||||
	s, _ := NewKubeControllerManagerOptions()
 | 
						s, _ := NewKubeControllerManagerOptions()
 | 
				
			||||||
	for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
 | 
						for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
 | 
				
			||||||
		fs.AddFlagSet(f)
 | 
							fs.AddFlagSet(f)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fgFlagName := "feature-gates"
 | 
						assertWatchListClientFeatureDefaultValue(t)
 | 
				
			||||||
	fg := fs.Lookup(fgFlagName)
 | 
						assertWatchListCommandLineDefaultValue(t, fs)
 | 
				
			||||||
	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)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWatchListClientFlagChange(t *testing.T) {
 | 
					func TestWatchListClientFlagChange(t *testing.T) {
 | 
				
			||||||
	assertWatchListClientFeatureDefaultValue(t)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
						fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
 | 
				
			||||||
	s, _ := NewKubeControllerManagerOptions()
 | 
						s, _ := NewKubeControllerManagerOptions()
 | 
				
			||||||
	for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
 | 
						for _, f := range s.Flags([]string{""}, []string{""}, nil).FlagSets {
 | 
				
			||||||
		fs.AddFlagSet(f)
 | 
							fs.AddFlagSet(f)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assertWatchListClientFeatureDefaultValue(t)
 | 
				
			||||||
 | 
						assertWatchListCommandLineDefaultValue(t, fs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	args := []string{fmt.Sprintf("--feature-gates=%v=true", clientgofeaturegate.WatchListClient)}
 | 
						args := []string{fmt.Sprintf("--feature-gates=%v=true", clientgofeaturegate.WatchListClient)}
 | 
				
			||||||
	if err := fs.Parse(args); err != nil {
 | 
						if err := fs.Parse(args); err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -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
 | 
					type sortedGCIgnoredResources []garbagecollectorconfig.GroupResource
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r sortedGCIgnoredResources) Len() int {
 | 
					func (r sortedGCIgnoredResources) Len() int {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user