Skip to content

Commit

Permalink
Make sure test cases use their own testing.T
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
squaremo committed Oct 18, 2023
1 parent d64732b commit 8360d98
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions controllers/leveltriggered/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const (
)

func TestReconcile(t *testing.T) {
g := testingutils.NewGomegaWithT(t)
ctx := context.Background()

t.Run("sets cluster not found and cluster unready condition", func(_ *testing.T) {
t.Run("sets cluster not found and cluster unready condition", func(t *testing.T) {
g := testingutils.NewGomegaWithT(t)
name := "pipeline-" + rand.String(5)
clusterName := "cluster-" + rand.String(5)
ns := testingutils.NewNamespace(ctx, g, k8sClient)
Expand All @@ -55,6 +55,7 @@ func TestReconcile(t *testing.T) {
})

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

name := "pipeline-" + rand.String(5)
Expand All @@ -76,7 +77,8 @@ func TestReconcile(t *testing.T) {
g.Expect(events[0].message).To(ContainSubstring("Updated pipeline"))
})

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

Expand All @@ -95,6 +97,7 @@ func TestReconcile(t *testing.T) {
})

t.Run("app status is recorded faithfully", func(t *testing.T) {
g := testingutils.NewGomegaWithT(t)
name := "pipeline-" + rand.String(5)
ns := testingutils.NewNamespace(ctx, g, k8sClient)
pipeline := newPipeline(ctx, g, name, ns.Name, nil)
Expand Down Expand Up @@ -139,7 +142,7 @@ func getTargetStatus(g Gomega, pipeline *v1alpha1.Pipeline, envName string, targ

func checkReadyCondition(ctx context.Context, g Gomega, n types.NamespacedName, status metav1.ConditionStatus, reason string) {
pipeline := &v1alpha1.Pipeline{}
assrt := g.Eventually(func() []metav1.Condition {
assrt := g.EventuallyWithOffset(1, func() []metav1.Condition {
err := k8sClient.Get(ctx, n, pipeline)
if err != nil {
return nil
Expand Down

0 comments on commit 8360d98

Please sign in to comment.