kubelet: Make the test fail if (*FakeRuntime).Assert fails

This commit is contained in:
Geonju Kim
2021-02-11 16:37:07 +09:00
parent c198632a12
commit fc4a29da2c
3 changed files with 26 additions and 22 deletions

View File

@@ -18,11 +18,11 @@ package testing
import (
"context"
"fmt"
"io"
"net/url"
"reflect"
"sync"
"testing"
"time"
v1 "k8s.io/api/core/v1"
@@ -58,6 +58,7 @@ type FakeRuntime struct {
Err error
InspectErr error
StatusErr error
T *testing.T
}
const FakeHost = "localhost:12345"
@@ -135,39 +136,40 @@ func (f *FakeRuntime) UpdatePodCIDR(c string) error {
return nil
}
func (f *FakeRuntime) assertList(expect []string, test []string) error {
func (f *FakeRuntime) assertList(expect []string, test []string) bool {
if !reflect.DeepEqual(expect, test) {
return fmt.Errorf("expected %#v, got %#v", expect, test)
f.T.Errorf("AssertList: expected %#v, got %#v", expect, test)
return false
}
return nil
return true
}
// AssertCalls test if the invoked functions are as expected.
func (f *FakeRuntime) AssertCalls(calls []string) error {
func (f *FakeRuntime) AssertCalls(calls []string) bool {
f.Lock()
defer f.Unlock()
return f.assertList(calls, f.CalledFunctions)
}
func (f *FakeRuntime) AssertStartedPods(pods []string) error {
func (f *FakeRuntime) AssertStartedPods(pods []string) bool {
f.Lock()
defer f.Unlock()
return f.assertList(pods, f.StartedPods)
}
func (f *FakeRuntime) AssertKilledPods(pods []string) error {
func (f *FakeRuntime) AssertKilledPods(pods []string) bool {
f.Lock()
defer f.Unlock()
return f.assertList(pods, f.KilledPods)
}
func (f *FakeRuntime) AssertStartedContainers(containers []string) error {
func (f *FakeRuntime) AssertStartedContainers(containers []string) bool {
f.Lock()
defer f.Unlock()
return f.assertList(containers, f.StartedContainers)
}
func (f *FakeRuntime) AssertKilledContainers(containers []string) error {
func (f *FakeRuntime) AssertKilledContainers(containers []string) bool {
f.Lock()
defer f.Unlock()
return f.assertList(containers, f.KilledContainers)