Skip to content

Commit 07ca9ad

Browse files
Merge pull request #1596 from benluddy/assertions-in-assertions
Replace assertions within async assertions.
2 parents 3aa7ff9 + 10f9241 commit 07ca9ad

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

test/e2e/crd_e2e_test.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package e2e
33
import (
44
"context"
55
"fmt"
6+
"time"
7+
68
"github.com/blang/semver"
79
. "github.com/onsi/ginkgo"
810
. "github.com/onsi/gomega"
@@ -13,7 +15,6 @@ import (
1315
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1416
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1517
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"time"
1718
)
1819

1920
var _ = Describe("CRD Versions", func() {
@@ -306,21 +307,33 @@ var _ = Describe("CRD Versions", func() {
306307
_, err = crc.OperatorsV1alpha1().Subscriptions(testNamespace).Update(context.TODO(), sub, metav1.UpdateOptions{})
307308
Expect(err).ToNot(HaveOccurred(), "could not update subscription")
308309

310+
subscriptionAtLatestWithDifferentInstallPlan := func(v *operatorsv1alpha1.Subscription) bool {
311+
return subscriptionStateAtLatestChecker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
312+
}
313+
309314
// fetch new subscription
310-
s, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
315+
s, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
311316
Expect(err).ToNot(HaveOccurred())
312317
Expect(s).ToNot(BeNil())
313318
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
314319

315320
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
316-
Eventually(func() bool {
317-
ip, err := crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
318-
Expect(err).ToNot(HaveOccurred(), "could not get installplan")
319-
320-
Expect(ip.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseFailed))
321-
Expect(ip.Status.Conditions[len(ip.Status.Conditions)-1].Message).To(ContainSubstring("risk of data loss"))
322-
return true
323-
}).Should(BeTrue())
321+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
322+
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
323+
}).Should(And(
324+
WithTransform(
325+
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase {
326+
return v.Status.Phase
327+
},
328+
Equal(operatorsv1alpha1.InstallPlanPhaseFailed),
329+
),
330+
WithTransform(
331+
func(v *operatorsv1alpha1.InstallPlan) string {
332+
return v.Status.Conditions[len(v.Status.Conditions)-1].Message
333+
},
334+
ContainSubstring("risk of data loss"),
335+
),
336+
))
324337
})
325338

326339
// Create a CRD on cluster with v1alpha1 (storage)
@@ -369,7 +382,9 @@ var _ = Describe("CRD Versions", func() {
369382
// wrap CRD update in a poll because of the object has been modified related errors
370383
Eventually(func() error {
371384
oldCRD, err = c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
372-
Expect(err).ToNot(HaveOccurred(), "error getting old CRD")
385+
if err != nil {
386+
return err
387+
}
373388
GinkgoT().Logf("old crd status stored versions: %#v", oldCRD.Status.StoredVersions)
374389

375390
// set v1alpha1 to no longer served
@@ -448,12 +463,12 @@ var _ = Describe("CRD Versions", func() {
448463
Expect(catalogCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
449464

450465
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
451-
Eventually(func() bool {
452-
ip, err := crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
453-
Expect(err).ToNot(HaveOccurred(), "could not get installplan")
454-
455-
return ip.Status.Phase == operatorsv1alpha1.InstallPlanPhaseFailed
456-
}).Should(BeTrue())
466+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
467+
return crc.OperatorsV1alpha1().InstallPlans(testNamespace).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
468+
}).Should(WithTransform(
469+
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase { return v.Status.Phase },
470+
Equal(operatorsv1alpha1.InstallPlanPhaseFailed),
471+
))
457472

458473
// update CRD status to remove the v1alpha1 stored version
459474
newCRD, err := c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})

test/e2e/gc_e2e_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,15 @@ var _ = Describe("Garbage collection for dependent resources", func() {
458458
})
459459

460460
It("OLM should have upgraded associated configmap in place", func() {
461-
Eventually(func() bool {
461+
Eventually(func() (string, error) {
462462
cfg, err := kubeClient.GetConfigMap(testNamespace, configmapName)
463463
if err != nil {
464-
return false
464+
return "", err
465465
}
466466
// check data in configmap to ensure it is the new data (configmap was updated in the newer bundle)
467467
// new value in the configmap is "updated-very-much"
468-
data := cfg.Data["special.how"]
469-
return data == "updated-very-much"
470-
}).Should(BeTrue())
468+
return cfg.Data["special.how"], nil
469+
}).Should(Equal("updated-very-much"))
471470
ctx.Ctx().Logf("dependent successfully updated after csv owner was updated")
472471
})
473472
})

test/e2e/packagemanifest_e2e_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
. "github.com/onsi/ginkgo"
1010
. "github.com/onsi/gomega"
1111
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
12-
"k8s.io/apimachinery/pkg/api/errors"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1413
"k8s.io/client-go/rest"
1514

@@ -264,11 +263,13 @@ var _ = Describe("Package Manifest API lists available Operators from Catalog So
264263
})
265264
It("should successfully update the CatalogSource field", func() {
266265

267-
Eventually(func() string {
266+
Eventually(func() (string, error) {
268267
pm, err := fetchPackageManifest(pmc, testNamespace, packageName,
269268
packageManifestHasStatus)
270-
Expect(err).NotTo(HaveOccurred(), "error getting package manifest after updating catsrc")
271-
return pm.Status.CatalogSourceDisplayName
269+
if err != nil {
270+
return "", err
271+
}
272+
return pm.Status.CatalogSourceDisplayName, nil
272273
}).Should(Equal(displayName))
273274
})
274275
})
@@ -286,11 +287,11 @@ func fetchPackageManifest(pmc pmversioned.Interface, namespace, name string, che
286287
var fetched *packagev1.PackageManifest
287288
var err error
288289

289-
Eventually(func() (bool, error) {
290+
EventuallyWithOffset(1, func() (bool, error) {
290291
ctx.Ctx().Logf("Polling...")
291292
fetched, err = pmc.OperatorsV1().PackageManifests(namespace).Get(context.TODO(), name, metav1.GetOptions{})
292-
if err != nil && !errors.IsNotFound(err) {
293-
return true, err
293+
if err != nil {
294+
return false, err
294295
}
295296
return check(fetched), nil
296297
}).Should(BeTrue())

0 commit comments

Comments
 (0)