Commit d1abc5c8 authored by John Calabrese's avatar John Calabrese

use subtest for table units

parent 4da73a5f
...@@ -26,7 +26,7 @@ import ( ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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)
} }
})
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment