mirror of https://github.com/k3s-io/k3s
Merge pull request #63659 from xchapter7x/pkg-scheduler-algorithm-priorities-util
Automatic merge from submit-queue (batch tested with PRs 65230, 57355, 59174, 63698, 63659). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. use subtest for table units (pkg-scheduler-algorithm-priorities-util) **What this PR does / why we need it**: Update scheduler's unit table tests to use subtest **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Special notes for your reviewer**: breaks up PR: https://github.com/kubernetes/kubernetes/pull/63281 /ref #63267 **Release note**: ```release-note This PR will leverage subtests on the existing table tests for the scheduler units. Some refactoring of error/status messages and functions to align with new approach. ```pull/8/head
commit
e486e8f1f9
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetNonzeroRequests(t *testing.T) {
|
func TestGetNonzeroRequests(t *testing.T) {
|
||||||
tds := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
requests v1.ResourceList
|
requests v1.ResourceList
|
||||||
expectedCPU int64
|
expectedCPU int64
|
||||||
|
@ -65,9 +65,11 @@ func TestGetNonzeroRequests(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, td := range tds {
|
for _, test := range tests {
|
||||||
realCPU, realMemory := GetNonzeroRequests(&td.requests)
|
t.Run(test.name, func(t *testing.T) {
|
||||||
assert.EqualValuesf(t, td.expectedCPU, realCPU, "Failed to test: %s", td.name)
|
realCPU, realMemory := GetNonzeroRequests(&test.requests)
|
||||||
assert.EqualValuesf(t, td.expectedMemory, realMemory, "Failed to test: %s", td.name)
|
assert.EqualValuesf(t, test.expectedCPU, realCPU, "Failed to test: %s", test.name)
|
||||||
|
assert.EqualValuesf(t, test.expectedMemory, realMemory, "Failed to test: %s", test.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,10 @@ func TestGetNamespacesFromPodAffinityTerm(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
realValue := GetNamespacesFromPodAffinityTerm(fakePod(), test.podAffinityTerm)
|
realValue := GetNamespacesFromPodAffinityTerm(fakePod(), test.podAffinityTerm)
|
||||||
assert.EqualValuesf(t, test.expectedValue, realValue, "Failed to test: %s", test.name)
|
assert.EqualValuesf(t, test.expectedValue, realValue, "Failed to test: %s", test.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +98,14 @@ func TestPodMatchesTermsNamespaceAndSelector(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
fakeTestPod := fakePod()
|
fakeTestPod := fakePod()
|
||||||
fakeTestPod.Namespace = test.podNamespaces
|
fakeTestPod.Namespace = test.podNamespaces
|
||||||
fakeTestPod.Labels = test.podLabels
|
fakeTestPod.Labels = test.podLabels
|
||||||
|
|
||||||
realValue := PodMatchesTermsNamespaceAndSelector(fakeTestPod, fakeNamespaces, fakeSelector)
|
realValue := PodMatchesTermsNamespaceAndSelector(fakeTestPod, fakeNamespaces, fakeSelector)
|
||||||
assert.EqualValuesf(t, test.expectedResult, realValue, "Faild to test: %s", test.name)
|
assert.EqualValuesf(t, test.expectedResult, realValue, "Faild to test: %s", test.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -248,7 +252,9 @@ func TestNodesHaveSameTopologyKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got := NodesHaveSameTopologyKey(test.nodeA, test.nodeB, test.topologyKey)
|
got := NodesHaveSameTopologyKey(test.nodeA, test.nodeB, test.topologyKey)
|
||||||
assert.Equalf(t, test.expected, got, "Failed to test: %s", test.name)
|
assert.Equalf(t, test.expected, got, "Failed to test: %s", test.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,13 @@ func TestGetControllerRef(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, td := range tds {
|
for _, td := range tds {
|
||||||
|
t.Run(td.name, func(t *testing.T) {
|
||||||
realOR := GetControllerRef(&td.pod)
|
realOR := GetControllerRef(&td.pod)
|
||||||
if td.expectedNil {
|
if td.expectedNil {
|
||||||
assert.Nilf(t, realOR, "Failed to test: %s", td.name)
|
assert.Nilf(t, realOR, "Failed to test: %s", td.name)
|
||||||
} else {
|
} else {
|
||||||
assert.Equalf(t, &td.expectedOR, realOR, "Failed to test: %s", td.name)
|
assert.Equalf(t, &td.expectedOR, realOR, "Failed to test: %s", td.name)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue