Skip to content

Commit

Permalink
Fixup TestWaitForPodSucceeded unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedld committed Apr 1, 2024
1 parent 8f5ac7f commit 6f3b074
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/skaffold/kubernetes/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
fakekubeclientset "k8s.io/client-go/kubernetes/fake"
clienttesting "k8s.io/client-go/testing"

"github.com/GoogleContainerTools/skaffold/v2/testutil"
)
Expand Down Expand Up @@ -62,6 +64,9 @@ func TestWaitForPodSucceeded(t *testing.T) {
pod := &v1.Pod{}
client := fakekubeclientset.NewSimpleClientset(pod)

client.PrependReactor("list", "pods", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil
})
fakeWatcher := watch.NewRaceFreeFake()
client.PrependWatchReactor("*", testutil.SetupFakeWatcher(fakeWatcher))
fakePods := client.CoreV1().Pods("")
Expand All @@ -78,12 +83,18 @@ func TestWaitForPodSucceeded(t *testing.T) {
switch phase {
case v1.PodPending, v1.PodRunning, v1.PodFailed, v1.PodSucceeded, v1.PodUnknown:
fakeWatcher.Modify(&v1.Pod{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "1",
},
Status: v1.PodStatus{
Phase: phase,
},
})
default:
fakeWatcher.Modify(&metav1.Status{
ListMeta: metav1.ListMeta{
ResourceVersion: "1",
},
Status: "Failure",
})
}
Expand Down

0 comments on commit 6f3b074

Please sign in to comment.