From 9b4d3fc4262ccd45325f79946fe2c98a9727b9c4 Mon Sep 17 00:00:00 2001 From: Jason Hall <jason@chainguard.dev> Date: Fri, 13 May 2022 09:31:18 -0400 Subject: [PATCH] Test that wantPatch cases actually call PATCH --- pkg/pod/entrypoint_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/pod/entrypoint_test.go b/pkg/pod/entrypoint_test.go index ecb4068fd44..6eff144c262 100644 --- a/pkg/pod/entrypoint_test.go +++ b/pkg/pod/entrypoint_test.go @@ -435,16 +435,22 @@ func TestUpdateReady(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() kubeclient := fakek8s.NewSimpleClientset(&c.pod) + patchCalled := false kubeclient.PrependReactor("patch", "pods", func(a k8stesting.Action) (bool, runtime.Object, error) { if !c.wantPatch { t.Fatal("Pod was patched unexpectedly") } + patchCalled = true return false, nil, nil }) if err := UpdateReady(ctx, kubeclient, c.pod); (err != nil) != c.wantErr { t.Errorf("UpdateReady (wantErr=%t): %v", c.wantErr, err) } + if c.wantPatch && !patchCalled { + t.Fatal("Pod was not patched") + } + got, err := kubeclient.CoreV1().Pods(c.pod.Namespace).Get(ctx, c.pod.Name, metav1.GetOptions{}) if err != nil { t.Errorf("Getting pod %q after update: %v", c.pod.Name, err)