mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Organize scheduler unit tests into subtests
This commit is contained in:
parent
645c40fcf6
commit
ebb6fb5b0c
@ -1146,6 +1146,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
nodes := makeNodeList([]string{"1"})
|
nodes := makeNodeList([]string{"1"})
|
||||||
|
|
||||||
plugin := st.FakeFilterPlugin{}
|
plugin := st.FakeFilterPlugin{}
|
||||||
@ -1182,6 +1183,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
|
|||||||
if test.expectedCount != plugin.NumFilterCalled {
|
if test.expectedCount != plugin.NumFilterCalled {
|
||||||
t.Errorf("predicate was called %d times, expected is %d", plugin.NumFilterCalled, test.expectedCount)
|
t.Errorf("predicate was called %d times, expected is %d", plugin.NumFilterCalled, test.expectedCount)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
pkg/scheduler/internal/cache/cache_test.go
vendored
8
pkg/scheduler/internal/cache/cache_test.go
vendored
@ -394,7 +394,8 @@ func TestDump(t *testing.T) {
|
|||||||
podsToAdd: []*v1.Pod{testPods[0]},
|
podsToAdd: []*v1.Pod{testPods[0]},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
cache := newSchedulerCache(ttl, time.Second, nil)
|
cache := newSchedulerCache(ttl, time.Second, nil)
|
||||||
for _, podToAssume := range tt.podsToAssume {
|
for _, podToAssume := range tt.podsToAssume {
|
||||||
if err := assumeAndFinishBinding(cache, podToAssume, now); err != nil {
|
if err := assumeAndFinishBinding(cache, podToAssume, now); err != nil {
|
||||||
@ -420,6 +421,7 @@ func TestDump(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(snapshot.AssumedPods, cache.assumedPods) {
|
if !reflect.DeepEqual(snapshot.AssumedPods, cache.assumedPods) {
|
||||||
t.Errorf("expect \n%+v; got \n%+v", cache.assumedPods, snapshot.AssumedPods)
|
t.Errorf("expect \n%+v; got \n%+v", cache.assumedPods, snapshot.AssumedPods)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,7 +649,8 @@ func TestUpdatePodAndGet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
cache := newSchedulerCache(ttl, time.Second, nil)
|
cache := newSchedulerCache(ttl, time.Second, nil)
|
||||||
|
|
||||||
if err := tt.handler(cache, tt.pod); err != nil {
|
if err := tt.handler(cache, tt.pod); err != nil {
|
||||||
@ -667,6 +670,7 @@ func TestUpdatePodAndGet(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(tt.podToUpdate, cachedPod) {
|
if !reflect.DeepEqual(tt.podToUpdate, cachedPod) {
|
||||||
t.Fatalf("pod get=%s, want=%s", cachedPod, tt.podToUpdate)
|
t.Fatalf("pod get=%s, want=%s", cachedPod, tt.podToUpdate)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -82,11 +83,13 @@ func TestGetNodeImageStates(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for i, test := range tests {
|
||||||
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
imageStates := getNodeImageStates(test.node, test.imageExistenceMap)
|
imageStates := getNodeImageStates(test.node, test.imageExistenceMap)
|
||||||
if !reflect.DeepEqual(test.expected, imageStates) {
|
if !reflect.DeepEqual(test.expected, imageStates) {
|
||||||
t.Errorf("expected: %#v, got: %#v", test.expected, imageStates)
|
t.Errorf("expected: %#v, got: %#v", test.expected, imageStates)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,10 +171,12 @@ func TestCreateImageExistenceMap(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for i, test := range tests {
|
||||||
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
imageMap := createImageExistenceMap(test.nodes)
|
imageMap := createImageExistenceMap(test.nodes)
|
||||||
if !reflect.DeepEqual(test.expected, imageMap) {
|
if !reflect.DeepEqual(test.expected, imageMap) {
|
||||||
t.Errorf("expected: %#v, got: %#v", test.expected, imageMap)
|
t.Errorf("expected: %#v, got: %#v", test.expected, imageMap)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,10 +111,12 @@ func TestMoreImportantPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range tests {
|
for k, v := range tests {
|
||||||
|
t.Run(k, func(t *testing.T) {
|
||||||
got := MoreImportantPod(v.p1, v.p2)
|
got := MoreImportantPod(v.p1, v.p2)
|
||||||
if got != v.expected {
|
if got != v.expected {
|
||||||
t.Errorf("%s failed, expected %t but got %t", k, v.expected, got)
|
t.Errorf("expected %t but got %t", v.expected, got)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user