Skip to content

Commit 2db1a64

Browse files
authored
Fix test context (#57)
* feat: add end to end tests for the model validation operator, including status and metrics checks Signed-off-by: Kevin Conner <[email protected]> * bug: fix context and gomega usage in tests Signed-off-by: Kevin Conner <[email protected]> --------- Signed-off-by: Kevin Conner <[email protected]>
1 parent dc68cc4 commit 2db1a64

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

internal/controller/pod_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var _ = Describe("PodReconciler", func() {
116116
Expect(removeEvents).To(HaveLen(1))
117117
Expect(removeEvents[0]).To(Equal(pod.UID))
118118

119-
Eventually(func() []string {
119+
Eventually(ctx, func(ctx context.Context) []string {
120120
updatedPod := &corev1.Pod{}
121121
err := fakeClient.Get(ctx, req.NamespacedName, updatedPod)
122122
if err != nil {

internal/tracker/status_tracker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func expectPodCount(
4343
mvKey types.NamespacedName,
4444
injected, uninjected, orphaned int32,
4545
) {
46-
Eventually(func() bool {
46+
Eventually(ctx, func(ctx context.Context) bool {
4747
updatedMV := testutil.GetModelValidationFromClientExpected(ctx, fakeClient, mvKey)
4848
return updatedMV.Status.InjectedPodCount == injected &&
4949
updatedMV.Status.UninjectedPodCount == uninjected &&

internal/webhooks/pod_webhook_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ var _ = Describe("Pod webhook", func() {
9494

9595
By("Checking that validation sidecar was created")
9696
found := &corev1.Pod{}
97-
Eventually(func() error {
97+
Eventually(ctx, func(ctx context.Context) error {
9898
return k8sClient.Get(ctx, typeNamespaceName, found)
99-
}).Should(Succeed())
99+
}, 5*time.Second).Should(Succeed())
100100

101-
Eventually(
102-
func(_ Gomega) []corev1.Container {
103-
Expect(k8sClient.Get(ctx, typeNamespaceName, found)).To(Succeed())
101+
Eventually(ctx,
102+
func(g Gomega, ctx context.Context) []corev1.Container {
103+
g.Expect(k8sClient.Get(ctx, typeNamespaceName, found)).To(Succeed())
104104
return found.Spec.InitContainers
105-
},
105+
}, 5*time.Second,
106106
).Should(And(
107107
WithTransform(func(containers []corev1.Container) int { return len(containers) }, Equal(1)),
108108
WithTransform(
@@ -126,17 +126,17 @@ var _ = Describe("Pod webhook", func() {
126126

127127
By("Waiting for pod to be injected")
128128
found := &corev1.Pod{}
129-
Eventually(func() []corev1.Container {
129+
Eventually(ctx, func(ctx context.Context) []corev1.Container {
130130
_ = k8sClient.Get(ctx, types.NamespacedName{Name: "tracked-pod", Namespace: Namespace}, found)
131131
return found.Spec.InitContainers
132-
}).Should(HaveLen(1))
132+
}, 5*time.Second).Should(HaveLen(1))
133133

134134
err = statusTracker.ProcessPodEvent(ctx, found)
135135
Expect(err).To(Not(HaveOccurred()))
136136

137137
By("Checking ModelValidation status was updated")
138138
mv := &v1alpha1.ModelValidation{}
139-
Eventually(func() int32 {
139+
Eventually(ctx, func(ctx context.Context) int32 {
140140
_ = k8sClient.Get(ctx, typeNamespaceName, mv)
141141
return mv.Status.InjectedPodCount
142142
}, 5*time.Second).Should(BeNumerically(">", 0))

0 commit comments

Comments
 (0)