Skip to content

Commit f95ef47

Browse files
authored
Remove test catalog setup from Before/AfterSuite (#534)
This removes dependency between tests and prevents cascading failures Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 208ca15 commit f95ef47

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

test/e2e/e2e_suite_test.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package e2e
22

33
import (
44
"context"
5-
"os"
65
"testing"
76
"time"
87

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

15-
"k8s.io/apimachinery/pkg/api/errors"
1614
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1715
"k8s.io/apimachinery/pkg/runtime"
18-
"k8s.io/apimachinery/pkg/types"
1916
"k8s.io/client-go/rest"
2017
ctrl "sigs.k8s.io/controller-runtime"
2118
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -27,9 +24,8 @@ import (
2724
)
2825

2926
var (
30-
cfg *rest.Config
31-
c client.Client
32-
operatorCatalog *catalogd.Catalog
27+
cfg *rest.Config
28+
c client.Client
3329
)
3430

3531
const (
@@ -63,11 +59,6 @@ var _ = BeforeSuite(func() {
6359

6460
c, err = client.New(cfg, client.Options{Scheme: scheme})
6561
Expect(err).To(Not(HaveOccurred()))
66-
67-
ctx := context.Background()
68-
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, os.Getenv(testCatalogRefEnvVar))
69-
Expect(err).ToNot(HaveOccurred())
70-
7162
})
7263

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

8672
// createTestCatalog will create a new catalog on the test cluster, provided

test/e2e/install_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,32 @@ const (
3434

3535
var _ = Describe("Operator Install", func() {
3636
var (
37-
ctx context.Context
38-
operatorName string
39-
operator *operatorv1alpha1.Operator
37+
ctx context.Context
38+
operatorCatalog *catalogd.Catalog
39+
operatorName string
40+
operator *operatorv1alpha1.Operator
4041
)
4142
When("An operator is installed from an operator catalog", func() {
4243
BeforeEach(func() {
4344
ctx = context.Background()
45+
var err error
46+
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, os.Getenv(testCatalogRefEnvVar))
47+
Expect(err).ToNot(HaveOccurred())
48+
4449
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
4550
operator = &operatorv1alpha1.Operator{
4651
ObjectMeta: metav1.ObjectMeta{
4752
Name: operatorName,
4853
},
4954
}
5055
})
56+
AfterEach(func() {
57+
Expect(c.Delete(ctx, operatorCatalog)).To(Succeed())
58+
Eventually(func(g Gomega) {
59+
err := c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
60+
g.Expect(errors.IsNotFound(err)).To(BeTrue())
61+
}).Should(Succeed())
62+
})
5163
When("the operator bundle format is registry+v1", func() {
5264
BeforeEach(func() {
5365
operator.Spec = operatorv1alpha1.OperatorSpec{

0 commit comments

Comments
 (0)