Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Add Global operator + namespaced kamelet test #2955

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions e2e/builder/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRunGlobalInstall(t *testing.T) {
}
}

test := func(operatorNamespace string) {
WithGlobalOperatorNamespace(t, func(operatorNamespace string) {
Expect(Kamel("install", "-n", operatorNamespace, "--global", "--force").Execute()).To(Succeed())

t.Run("Global test on namespace with platform", func(t *testing.T) {
Expand Down Expand Up @@ -143,18 +143,7 @@ func TestRunGlobalInstall(t *testing.T) {
})

Expect(Kamel("uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles").Execute()).To(Succeed())
}

ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
// global operators are always installed in the openshift-operators namespace
RegisterTestingT(t)
test("openshift-operators")
} else {
// create new namespace for the global operator
WithNewTestNamespace(t, test)
}
})
}

func integrationKitsToNamesTransform() func([]v1.IntegrationKit) []string {
Expand Down
49 changes: 29 additions & 20 deletions e2e/common/cli/global_kamelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,41 @@ func TestRunGlobalKamelet(t *testing.T) {
}
}

test := func(operatorNamespace string) {
WithGlobalOperatorNamespace(t, func(operatorNamespace string) {
Expect(Kamel("install", "-n", operatorNamespace, "--global", "--force").Execute()).To(Succeed())

Expect(CreateTimerKamelet(operatorNamespace, "my-own-timer-source")()).To(Succeed())
t.Run("Global operator + namespaced kamelet test", func(t *testing.T) {

// NS2: namespace without operator
WithNewTestNamespace(t, func(ns2 string) {
Expect(Kamel("install", "-n", ns2, "--skip-operator-setup", "--olm=false").Execute()).To(Succeed())
// NS2: namespace without operator
WithNewTestNamespace(t, func(ns2 string) {
Expect(CreateTimerKamelet(ns2, "my-own-timer-source")()).To(Succeed())

Expect(Kamel("run", "-n", ns2, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns2, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns2, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world"))
Expect(Kamel("delete", "--all", "-n", ns2).Execute()).To(Succeed())
Expect(Kamel("install", "-n", ns2, "--skip-operator-setup", "--olm=false").Execute()).To(Succeed())

Expect(Kamel("run", "-n", ns2, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns2, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns2, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world"))
Expect(Kamel("delete", "--all", "-n", ns2).Execute()).To(Succeed())
})
})

t.Run("Global operator + global kamelet test", func(t *testing.T) {

Expect(CreateTimerKamelet(operatorNamespace, "my-own-timer-source")()).To(Succeed())

// NS3: namespace without operator
WithNewTestNamespace(t, func(ns3 string) {
Expect(Kamel("install", "-n", ns3, "--skip-operator-setup", "--olm=false").Execute()).To(Succeed())

Expect(Kamel("run", "-n", ns3, "files/timer-kamelet-usage.groovy").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns3, "timer-kamelet-usage"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns3, "timer-kamelet-usage"), TestTimeoutShort).Should(ContainSubstring("Hello world"))
Expect(Kamel("delete", "--all", "-n", ns3).Execute()).To(Succeed())
Expect(TestClient().Delete(TestContext, Kamelet("my-own-timer-source", operatorNamespace)())).To(Succeed())
})
})

Expect(Kamel("uninstall", "-n", operatorNamespace, "--skip-crd", "--skip-cluster-roles=false", "--skip-cluster-role-bindings=false").Execute()).To(Succeed())
}
})

ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
// global operators are always installed in the openshift-operators namespace
RegisterTestingT(t)
test("openshift-operators")
}else {
// create new namespace for the global operator
WithNewTestNamespace(t, test)
}
}
13 changes: 13 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -1642,6 +1643,18 @@ func WithNewTestNamespace(t *testing.T, doRun func(string)) {
InvokeUserTestCode(t, ns.GetName(), doRun)
}

func WithGlobalOperatorNamespace(t *testing.T, test func(string)) {
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
if ocp {
// global operators are always installed in the openshift-operators namespace
InvokeUserTestCode(t, "openshift-operators", test)
}else {
// create new namespace for the global operator
WithNewTestNamespace(t, test)
}
}

func WithNewTestNamespaceWithKnativeBroker(t *testing.T, doRun func(string)) {
ns := NewTestNamespace(true)
defer DeleteTestNamespace(t, ns)
Expand Down