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:
Kubernetes Submit Queue 2017-08-26 02:05:29 -07:00 committed by GitHub
commit d660a41f36

View File

@ -30,6 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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/kubernetes/pkg/credentialprovider"
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)
}
func verifyFakeContainerList(fakeRuntime *apitest.FakeRuntimeService, expected []string) ([]string, bool) {
actual := []string{}
func verifyFakeContainerList(fakeRuntime *apitest.FakeRuntimeService, expected sets.String) (sets.String, bool) {
actual := sets.NewString()
for _, c := range fakeRuntime.Containers {
actual = append(actual, c.Id)
actual.Insert(c.Id)
}
sort.Sort(sort.StringSlice(actual))
sort.Sort(sort.StringSlice(expected))
return actual, reflect.DeepEqual(expected, actual)
return actual, actual.Equal(expected)
}
type containerRecord struct {
@ -618,9 +616,9 @@ func TestPruneInitContainers(t *testing.T) {
assert.NoError(t, err)
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 {
t.Errorf("expected %q, got %q", expectedContainers, actual)
t.Errorf("expected %v, got %v", expectedContainers, actual)
}
}