Merge pull request #98696 from gavinfish/sched-ut

Scheduler: organize scheduler unit tests into subtests
This commit is contained in:
Kubernetes Prow Robot 2021-02-02 14:06:49 -08:00 committed by GitHub
commit 686a5cee36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 85 deletions

View File

@ -1146,6 +1146,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
nodes := makeNodeList([]string{"1"})
plugin := st.FakeFilterPlugin{}
@ -1182,6 +1183,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
if test.expectedCount != plugin.NumFilterCalled {
t.Errorf("predicate was called %d times, expected is %d", plugin.NumFilterCalled, test.expectedCount)
}
})
}
}

View File

@ -394,7 +394,8 @@ func TestDump(t *testing.T) {
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)
for _, podToAssume := range tt.podsToAssume {
if err := assumeAndFinishBinding(cache, podToAssume, now); err != nil {
@ -420,6 +421,7 @@ func TestDump(t *testing.T) {
if !reflect.DeepEqual(snapshot.AssumedPods, cache.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)
if err := tt.handler(cache, tt.pod); err != nil {
@ -667,6 +670,7 @@ func TestUpdatePodAndGet(t *testing.T) {
if !reflect.DeepEqual(tt.podToUpdate, cachedPod) {
t.Fatalf("pod get=%s, want=%s", cachedPod, tt.podToUpdate)
}
})
}
}

View File

@ -17,6 +17,7 @@ limitations under the License.
package cache
import (
"fmt"
"reflect"
"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)
if !reflect.DeepEqual(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)
if !reflect.DeepEqual(test.expected, imageMap) {
t.Errorf("expected: %#v, got: %#v", test.expected, imageMap)
}
})
}
}

View File

@ -111,10 +111,12 @@ func TestMoreImportantPod(t *testing.T) {
}
for k, v := range tests {
t.Run(k, func(t *testing.T) {
got := MoreImportantPod(v.p1, v.p2)
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)
}
})
}
}