Merge pull request #51101 from zhangxiaoyu-zidif/refactor-kubelet-kuberuntime-test
Automatic merge from submit-queue (batch tested with PRs 51054, 51101, 50031, 51296, 51173) Refactor kuberuntime test case with sets.String **What this PR does / why we need it**: change to make got and want use sets.String instead, since that is both safe and more clearly shows the intent. ref: https://github.com/kubernetes/kubernetes/pull/50554 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes https://github.com/kubernetes/kubernetes/issues/51396 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
		@@ -30,6 +30,7 @@ import (
 | 
				
			|||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	kubetypes "k8s.io/apimachinery/pkg/types"
 | 
						kubetypes "k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/util/sets"
 | 
				
			||||||
	"k8s.io/client-go/util/flowcontrol"
 | 
						"k8s.io/client-go/util/flowcontrol"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/credentialprovider"
 | 
						"k8s.io/kubernetes/pkg/credentialprovider"
 | 
				
			||||||
	apitest "k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
 | 
						apitest "k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
 | 
				
			||||||
@@ -216,15 +217,12 @@ func verifyPods(a, b []*kubecontainer.Pod) bool {
 | 
				
			|||||||
	return reflect.DeepEqual(a, b)
 | 
						return reflect.DeepEqual(a, b)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func verifyFakeContainerList(fakeRuntime *apitest.FakeRuntimeService, expected []string) ([]string, bool) {
 | 
					func verifyFakeContainerList(fakeRuntime *apitest.FakeRuntimeService, expected sets.String) (sets.String, bool) {
 | 
				
			||||||
	actual := []string{}
 | 
						actual := sets.NewString()
 | 
				
			||||||
	for _, c := range fakeRuntime.Containers {
 | 
						for _, c := range fakeRuntime.Containers {
 | 
				
			||||||
		actual = append(actual, c.Id)
 | 
							actual.Insert(c.Id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sort.Sort(sort.StringSlice(actual))
 | 
						return actual, actual.Equal(expected)
 | 
				
			||||||
	sort.Sort(sort.StringSlice(expected))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return actual, reflect.DeepEqual(expected, actual)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type containerRecord struct {
 | 
					type containerRecord struct {
 | 
				
			||||||
@@ -618,9 +616,9 @@ func TestPruneInitContainers(t *testing.T) {
 | 
				
			|||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m.pruneInitContainersBeforeStart(pod, podStatus)
 | 
						m.pruneInitContainersBeforeStart(pod, podStatus)
 | 
				
			||||||
	expectedContainers := []string{fakes[0].Id, fakes[2].Id}
 | 
						expectedContainers := sets.NewString(fakes[0].Id, fakes[2].Id)
 | 
				
			||||||
	if actual, ok := verifyFakeContainerList(fakeRuntime, expectedContainers); !ok {
 | 
						if actual, ok := verifyFakeContainerList(fakeRuntime, expectedContainers); !ok {
 | 
				
			||||||
		t.Errorf("expected %q, got %q", expectedContainers, actual)
 | 
							t.Errorf("expected %v, got %v", expectedContainers, actual)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user