Skip to content

Commit 52e0f52

Browse files
committed
node: cpumgr: test: use Equals for comparison
There's no need to use the generic reflect.DeepEqual, we can use the cpuset Equals method in tests, which is more idiomatic and a tad clearer. Signed-off-by: Francesco Romani <[email protected]>
1 parent a07510f commit 52e0f52

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/kubelet/cm/cpumanager/policy_static_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ func runStaticPolicyTestCase(t *testing.T, testCase staticPolicyTest) {
667667
testCase.description, container.Name, st.assignments)
668668
}
669669

670-
if !reflect.DeepEqual(cset, testCase.expCSet) {
670+
if !cset.Equals(testCase.expCSet) {
671671
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v",
672672
testCase.description, testCase.expCSet, cset)
673673
}
@@ -732,15 +732,15 @@ func TestStaticPolicyReuseCPUs(t *testing.T) {
732732
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
733733
policy.Allocate(st, pod, &container)
734734
}
735-
if !reflect.DeepEqual(st.defaultCPUSet, testCase.expCSetAfterAlloc) {
735+
if !st.defaultCPUSet.Equals(testCase.expCSetAfterAlloc) {
736736
t.Errorf("StaticPolicy Allocate() error (%v). expected default cpuset %v but got %v",
737737
testCase.description, testCase.expCSetAfterAlloc, st.defaultCPUSet)
738738
}
739739

740740
// remove
741741
policy.RemoveContainer(st, string(pod.UID), testCase.containerName)
742742

743-
if !reflect.DeepEqual(st.defaultCPUSet, testCase.expCSetAfterRemove) {
743+
if !st.defaultCPUSet.Equals(testCase.expCSetAfterRemove) {
744744
t.Errorf("StaticPolicy RemoveContainer() error (%v). expected default cpuset %v but got %v",
745745
testCase.description, testCase.expCSetAfterRemove, st.defaultCPUSet)
746746
}
@@ -792,7 +792,7 @@ func TestStaticPolicyDoNotReuseCPUs(t *testing.T) {
792792
testCase.description, err)
793793
}
794794
}
795-
if !reflect.DeepEqual(st.defaultCPUSet, testCase.expCSetAfterAlloc) {
795+
if !st.defaultCPUSet.Equals(testCase.expCSetAfterAlloc) {
796796
t.Errorf("StaticPolicy Allocate() error (%v). expected default cpuset %v but got %v",
797797
testCase.description, testCase.expCSetAfterAlloc, st.defaultCPUSet)
798798
}
@@ -870,7 +870,7 @@ func TestStaticPolicyRemove(t *testing.T) {
870870

871871
policy.RemoveContainer(st, testCase.podUID, testCase.containerName)
872872

873-
if !reflect.DeepEqual(st.defaultCPUSet, testCase.expCSet) {
873+
if !st.defaultCPUSet.Equals(testCase.expCSet) {
874874
t.Errorf("StaticPolicy RemoveContainer() error (%v). expected default cpuset %v but got %v",
875875
testCase.description, testCase.expCSet, st.defaultCPUSet)
876876
}
@@ -973,7 +973,7 @@ func TestTopologyAwareAllocateCPUs(t *testing.T) {
973973
continue
974974
}
975975

976-
if !reflect.DeepEqual(tc.expCSet, cset) {
976+
if !tc.expCSet.Equals(cset) {
977977
t.Errorf("StaticPolicy allocateCPUs() error (%v). expected CPUSet %v but got %v",
978978
tc.description, tc.expCSet, cset)
979979
}
@@ -1152,7 +1152,7 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
11521152
testCase.description, container.Name, st.assignments)
11531153
}
11541154

1155-
if !reflect.DeepEqual(cset, testCase.expCSet) {
1155+
if !cset.Equals(testCase.expCSet) {
11561156
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v",
11571157
testCase.description, testCase.expCSet, cset)
11581158
}

0 commit comments

Comments
 (0)