Skip to content

Commit

Permalink
Use condition checker with gomega WithT
Browse files Browse the repository at this point in the history
This allows using the condition checker as a test helper with proper
test like assertion failure and stacktrace.

Signed-off-by: Sunny <[email protected]>
  • Loading branch information
darkowlzz committed Mar 14, 2023
1 parent 587887f commit fd22b49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions controllers/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestImagePolicyReconciler_calculateImageFromRepoTags(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imagePolicyNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &pol)
checker.WithT(g).CheckErr(ctx, &pol)

g.Expect(testEnv.Delete(ctx, &pol)).To(Succeed())
})
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestImagePolicyReconciler_filterTags(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imagePolicyNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &pol)
checker.WithT(g).CheckErr(ctx, &pol)

g.Expect(testEnv.Delete(ctx, &pol)).To(Succeed())
})
Expand Down Expand Up @@ -519,7 +519,7 @@ func TestImagePolicyReconciler_accessImageRepo(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imagePolicyNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &pol)
checker.WithT(g).CheckErr(ctx, &pol)

g.Expect(testEnv.Delete(ctx, &pol)).To(Succeed())
})
Expand Down
18 changes: 9 additions & 9 deletions controllers/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestImageRepositoryReconciler_canonicalImageName(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestImageRepositoryReconciler_fetchImageTags(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestImageRepositoryReconciler_reconcileAtAnnotation(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestImageRepositoryReconciler_authRegistry(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestImageRepositoryReconciler_imageAttribute_schemePrefix(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestImageRepositoryReconciler_imageAttribute_withTag(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestImageRepositoryReconciler_imageAttribute_hostPort(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestImageRepositoryReconciler_authRegistryWithServiceAccount(t *testing.T)
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
Expand Down Expand Up @@ -585,7 +585,7 @@ func TestImageRepositoryReconciler_ScanPublicRepos(t *testing.T) {
// Check if the object status is valid.
condns := &conditionscheck.Conditions{NegativePolarity: imageRepositoryNegativeConditions}
checker := conditionscheck.NewChecker(testEnv.Client, condns)
checker.CheckErr(ctx, &repo)
checker.WithT(g).CheckErr(ctx, &repo)

g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
})
Expand Down

0 comments on commit fd22b49

Please sign in to comment.