Skip to content

Commit

Permalink
Remove test catalog setup from Before/AfterSuite (#534)
Browse files Browse the repository at this point in the history
This removes dependency between tests and prevents cascading failures

Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola authored Nov 10, 2023
1 parent 208ca15 commit f95ef47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
18 changes: 2 additions & 16 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e

import (
"context"
"os"
"testing"
"time"

Expand All @@ -12,10 +11,8 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/env"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,9 +24,8 @@ import (
)

var (
cfg *rest.Config
c client.Client
operatorCatalog *catalogd.Catalog
cfg *rest.Config
c client.Client
)

const (
Expand Down Expand Up @@ -63,11 +59,6 @@ var _ = BeforeSuite(func() {

c, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).To(Not(HaveOccurred()))

ctx := context.Background()
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, os.Getenv(testCatalogRefEnvVar))
Expect(err).ToNot(HaveOccurred())

})

var _ = AfterSuite(func() {
Expand All @@ -76,11 +67,6 @@ var _ = AfterSuite(func() {
// get all the artifacts from the test run and save them to the artifact path
getArtifactsOutput(ctx, basePath)
}
Expect(c.Delete(ctx, operatorCatalog)).To(Succeed())
Eventually(func(g Gomega) {
err := c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
g.Expect(errors.IsNotFound(err)).To(BeTrue())
}).Should(Succeed())
})

// createTestCatalog will create a new catalog on the test cluster, provided
Expand Down
18 changes: 15 additions & 3 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,32 @@ const (

var _ = Describe("Operator Install", func() {
var (
ctx context.Context
operatorName string
operator *operatorv1alpha1.Operator
ctx context.Context
operatorCatalog *catalogd.Catalog
operatorName string
operator *operatorv1alpha1.Operator
)
When("An operator is installed from an operator catalog", func() {
BeforeEach(func() {
ctx = context.Background()
var err error
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, os.Getenv(testCatalogRefEnvVar))
Expect(err).ToNot(HaveOccurred())

operatorName = fmt.Sprintf("operator-%s", rand.String(8))
operator = &operatorv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{
Name: operatorName,
},
}
})
AfterEach(func() {
Expect(c.Delete(ctx, operatorCatalog)).To(Succeed())
Eventually(func(g Gomega) {
err := c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
g.Expect(errors.IsNotFound(err)).To(BeTrue())
}).Should(Succeed())
})
When("the operator bundle format is registry+v1", func() {
BeforeEach(func() {
operator.Spec = operatorv1alpha1.OperatorSpec{
Expand Down

0 comments on commit f95ef47

Please sign in to comment.