Skip to content

Commit b4d8755

Browse files
committed
Make sure test cases use their own testing.T
If you use the Gomega or *testing.T from the outer scope, passes and fails are not reported against individual tests correctly. Signed-off-by: Michael Bridgen <[email protected]>
1 parent 40949f2 commit b4d8755

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

controllers/leveltriggered/controller_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ const (
3030
)
3131

3232
func TestReconcile(t *testing.T) {
33-
g := testingutils.NewGomegaWithT(t)
3433
ctx := context.Background()
3534

36-
t.Run("sets cluster not found and cluster unready condition", func(_ *testing.T) {
35+
t.Run("sets cluster not found and cluster unready condition", func(t *testing.T) {
36+
g := testingutils.NewGomegaWithT(t)
3737
name := "pipeline-" + rand.String(5)
3838
clusterName := "cluster-" + rand.String(5)
3939
ns := testingutils.NewNamespace(ctx, g, k8sClient)
@@ -58,6 +58,7 @@ func TestReconcile(t *testing.T) {
5858
})
5959

6060
t.Run("sets reconciliation succeeded condition for remote cluster", func(t *testing.T) {
61+
g := testingutils.NewGomegaWithT(t)
6162
t.Skip("remote clusters not supported yet")
6263

6364
name := "pipeline-" + rand.String(5)
@@ -79,7 +80,8 @@ func TestReconcile(t *testing.T) {
7980
g.Expect(events[0].message).To(ContainSubstring("Updated pipeline"))
8081
})
8182

82-
t.Run("sets reconciliation succeeded condition without clusterRef", func(_ *testing.T) {
83+
t.Run("sets reconciliation succeeded condition without clusterRef", func(t *testing.T) {
84+
g := testingutils.NewGomegaWithT(t)
8385
name := "pipeline-" + rand.String(5)
8486
ns := testingutils.NewNamespace(ctx, g, k8sClient)
8587

@@ -98,6 +100,7 @@ func TestReconcile(t *testing.T) {
98100
})
99101

100102
t.Run("app status is recorded faithfully", func(t *testing.T) {
103+
g := testingutils.NewGomegaWithT(t)
101104
name := "pipeline-" + rand.String(5)
102105
ns := testingutils.NewNamespace(ctx, g, k8sClient)
103106
pipeline := newPipeline(ctx, g, name, ns.Name, nil)
@@ -126,6 +129,7 @@ func TestReconcile(t *testing.T) {
126129
})
127130

128131
t.Run("promotes revision to all environments", func(t *testing.T) {
132+
g := testingutils.NewGomegaWithT(t)
129133
mockStrategy := setStrategyRegistry(t, pipelineReconciler)
130134
mockStrategy.EXPECT().Handles(gomock.Any()).Return(true).AnyTimes()
131135

@@ -243,6 +247,7 @@ func TestReconcile(t *testing.T) {
243247
})
244248

245249
t.Run("sets PipelinePending condition", func(t *testing.T) {
250+
g := testingutils.NewGomegaWithT(t)
246251
mockStrategy := setStrategyRegistry(t, pipelineReconciler)
247252
mockStrategy.EXPECT().Handles(gomock.Any()).Return(true).AnyTimes()
248253

@@ -351,7 +356,7 @@ func getTargetStatus(g Gomega, pipeline *v1alpha1.Pipeline, envName string, targ
351356

352357
func checkCondition(ctx context.Context, g Gomega, n types.NamespacedName, conditionType string, status metav1.ConditionStatus, reason string) {
353358
pipeline := &v1alpha1.Pipeline{}
354-
assrt := g.Eventually(func() metav1.Condition {
359+
assrt := g.EventuallyWithOffset(1, func() metav1.Condition {
355360
err := k8sClient.Get(ctx, n, pipeline)
356361
if err != nil {
357362
return metav1.Condition{}

0 commit comments

Comments
 (0)