mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 01:23:48 +00:00
Merge pull request #98986 from gjkim42/fix-runtime-assert
kubelet: Make the test fail if (*FakeRuntime).Assert fails
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user