forked from operator-framework/operator-lifecycle-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_test.go
134 lines (113 loc) · 4.02 KB
/
e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package e2e
import (
"context"
"flag"
"fmt"
"os"
"path"
"testing"
"time"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
)
var (
kubeConfigPath = flag.String(
"kubeconfig", "", "path to the kubeconfig file")
namespace = flag.String(
"namespace", "", "namespace where tests will run")
olmNamespace = flag.String(
"olmNamespace", "", "namespace where olm is running")
communityOperators = flag.String(
"communityOperators",
"quay.io/operator-framework/upstream-community-operators@sha256:098457dc5e0b6ca9599bd0e7a67809f8eca397907ca4d93597380511db478fec",
"reference to upstream-community-operators image",
)
dummyImage = flag.String(
"dummyImage",
"bitnami/nginx:latest",
"dummy image to treat as an operator in tests",
)
collectArtifactsScriptPath = flag.String(
"gather-artifacts-script-path",
"./collect-ci-artifacts.sh",
"configures the relative/absolute path to the script resposible for collecting CI artifacts",
)
testdataPath = flag.String(
"test-data-dir",
"./testdata",
"configures where to find the testdata directory",
)
testdataDir = ""
testNamespace = ""
operatorNamespace = ""
communityOperatorsImage = ""
junitDir = "junit"
)
func TestEndToEnd(t *testing.T) {
RegisterFailHandler(Fail)
SetDefaultEventuallyTimeout(1 * time.Minute)
SetDefaultEventuallyPollingInterval(1 * time.Second)
SetDefaultConsistentlyDuration(30 * time.Second)
SetDefaultConsistentlyPollingInterval(1 * time.Second)
// always configure a junit report when ARTIFACT_DIR has been set
if artifactsDir := os.Getenv("ARTIFACT_DIR"); artifactsDir != "" {
junitReporter := reporters.NewJUnitReporter(path.Join(artifactsDir, junitDir, fmt.Sprintf("junit_e2e_%02d.xml", config.GinkgoConfig.ParallelNode)))
RunSpecsWithDefaultAndCustomReporters(t, "End-to-end", []Reporter{junitReporter})
} else {
RunSpecs(t, "End-to-end")
}
}
var deprovision func() = func() {}
// This function initializes a client which is used to create an operator group for a given namespace
var _ = BeforeSuite(func() {
if kubeConfigPath != nil && *kubeConfigPath != "" {
// This flag can be deprecated in favor of the kubeconfig provisioner:
os.Setenv("KUBECONFIG", *kubeConfigPath)
}
if collectArtifactsScriptPath != nil && *collectArtifactsScriptPath != "" {
os.Setenv("E2E_ARTIFACT_SCRIPT", *collectArtifactsScriptPath)
}
testNamespace = *namespace
operatorNamespace = *olmNamespace
communityOperatorsImage = *communityOperators
testdataDir = *testdataPath
deprovision = ctx.MustProvision(ctx.Ctx())
ctx.MustInstall(ctx.Ctx())
var groups operatorsv1.OperatorGroupList
Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed())
if len(groups.Items) == 0 {
og := operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "opgroup",
Namespace: testNamespace,
},
}
Expect(ctx.Ctx().Client().Create(context.TODO(), &og)).To(Succeed())
}
// Tests can assume the group in the test namespace has been reconciled at least once.
Eventually(func() ([]operatorsv1.OperatorGroupStatus, error) {
var groups operatorsv1.OperatorGroupList
if err := ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace)); err != nil {
return nil, err
}
var statuses []operatorsv1.OperatorGroupStatus
for _, group := range groups.Items {
statuses = append(statuses, group.Status)
}
return statuses, nil
}).Should(And(
HaveLen(1),
ContainElement(Not(BeZero())),
))
_, err := fetchCatalogSourceOnStatus(ctx.Ctx().OperatorClient(), "operatorhubio-catalog", operatorNamespace, catalogSourceRegistryPodSynced)
Expect(err).NotTo(HaveOccurred())
})
var _ = AfterSuite(func() {
deprovision()
})