Skip to content

Commit f83b797

Browse files
committed
test(e2e): add E2E tests for kustomize uninstall
1 parent 18e0234 commit f83b797

File tree

6 files changed

+184
-50
lines changed

6 files changed

+184
-50
lines changed

e2e/namespace/install/kustomize/common.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
ExpectedOSClusterRoles = 1
5959
)
6060

61-
func ExecMake(t *testing.T, command *exec.Cmd) {
61+
func ExpectExecSucceed(t *testing.T, command *exec.Cmd) {
6262
t.Helper()
6363

6464
var cmdOut strings.Builder
@@ -74,14 +74,14 @@ func ExecMake(t *testing.T, command *exec.Cmd) {
7474
session, err := gexec.Start(command, &cmdOut, &cmdErr)
7575
session.Wait()
7676
Eventually(session).Should(gexec.Exit(0))
77-
assert.Nil(t, err)
77+
assert.NoError(t, err)
7878
assert.NotContains(t, strings.ToUpper(cmdErr.String()), "ERROR")
7979
}
8080

8181
//
82-
// Expect a make error with an exit code of 1
82+
// Expect a command error with an exit code of 1
8383
//
84-
func ExecMakeError(t *testing.T, command *exec.Cmd) {
84+
func ExpectExecError(t *testing.T, command *exec.Cmd) {
8585
t.Helper()
8686

8787
var cmdOut strings.Builder
@@ -97,7 +97,7 @@ func ExecMakeError(t *testing.T, command *exec.Cmd) {
9797
session, err := gexec.Start(command, &cmdOut, &cmdErr)
9898
session.Wait()
9999
Eventually(session).ShouldNot(gexec.Exit(0))
100-
assert.Nil(t, err)
100+
assert.NoError(t, err)
101101
assert.Contains(t, strings.ToUpper(cmdErr.String()), "ERROR")
102102
}
103103

e2e/namespace/install/kustomize/operator_test.go

+35-17
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727
"os"
2828
"testing"
2929

30+
corev1 "k8s.io/api/core/v1"
31+
3032
. "github.com/apache/camel-k/e2e/support"
3133
testutil "github.com/apache/camel-k/e2e/support/util"
3234
. "github.com/onsi/gomega"
3335
)
3436

35-
func TestBasicOperator(t *testing.T) {
37+
func TestOperatorBasic(t *testing.T) {
3638
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
3739
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
3840

@@ -43,18 +45,24 @@ func TestBasicOperator(t *testing.T) {
4345
defer Cleanup()
4446

4547
WithNewTestNamespace(t, func(ns string) {
46-
ExecMake(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
47-
ExecMake(t, Make("setup", fmt.Sprintf("NAMESPACE=%s", ns)))
48+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
49+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
50+
ExpectExecSucceed(t, Make("setup", namespaceArg))
4851
// Skip default kamelets installation for faster test runs
49-
ExecMake(t, Make("operator",
50-
fmt.Sprintf("NAMESPACE=%s", ns),
52+
ExpectExecSucceed(t, Make("operator",
53+
namespaceArg,
5154
"INSTALL_DEFAULT_KAMELETS=false"))
5255

56+
// Refresh the test client to account for the newly installed CRDs
57+
SyncClient()
58+
5359
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
60+
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
61+
Eventually(Platform(ns)).ShouldNot(BeNil())
5462
})
5563
}
5664

57-
func TestAlternativeImageOperator(t *testing.T) {
65+
func TestOperatorAlternativeImage(t *testing.T) {
5866
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
5967
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
6068

@@ -65,24 +73,27 @@ func TestAlternativeImageOperator(t *testing.T) {
6573
defer Cleanup()
6674

6775
WithNewTestNamespace(t, func(ns string) {
68-
69-
ExecMake(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
70-
ExecMake(t, Make("setup", fmt.Sprintf("NAMESPACE=%s", ns)))
76+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
77+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
78+
ExpectExecSucceed(t, Make("setup", namespaceArg))
7179

7280
// Skip default kamelets installation for faster test runs
7381
newImage := "quay.io/kameltest/kamel-operator"
7482
newTag := "1.1.1"
75-
ExecMake(t, Make("operator",
83+
ExpectExecSucceed(t, Make("operator",
7684
fmt.Sprintf("CUSTOM_IMAGE=%s", newImage),
7785
fmt.Sprintf("CUSTOM_VERSION=%s", newTag),
78-
fmt.Sprintf("NAMESPACE=%s", ns),
86+
namespaceArg,
7987
"INSTALL_DEFAULT_KAMELETS=false"))
8088

89+
// Refresh the test client to account for the newly installed CRDs
90+
SyncClient()
91+
8192
Eventually(OperatorImage(ns)).Should(Equal(fmt.Sprintf("%s:%s", newImage, newTag)))
8293
})
8394
}
8495

85-
func TestGlobalOperator(t *testing.T) {
96+
func TestOperatorGlobal(t *testing.T) {
8697
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
8798
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
8899

@@ -93,17 +104,22 @@ func TestGlobalOperator(t *testing.T) {
93104
defer Cleanup()
94105

95106
WithNewTestNamespace(t, func(ns string) {
96-
ExecMake(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
97-
ExecMake(t, Make("setup", fmt.Sprintf("NAMESPACE=%s", ns), "GLOBAL=true"))
107+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
108+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
109+
ExpectExecSucceed(t, Make("setup", namespaceArg, "GLOBAL=true"))
98110

99111
// Skip default kamelets installation for faster test runs
100-
ExecMake(t, Make("operator",
101-
fmt.Sprintf("NAMESPACE=%s", ns),
112+
ExpectExecSucceed(t, Make("operator",
113+
namespaceArg,
102114
"GLOBAL=true",
103115
"INSTALL_DEFAULT_KAMELETS=false"))
104116

117+
// Refresh the test client to account for the newly installed CRDs
118+
SyncClient()
119+
105120
podFunc := OperatorPod(ns)
106-
Eventually(podFunc).Should(Not(BeNil()))
121+
Eventually(podFunc).ShouldNot(BeNil())
122+
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
107123
pod := podFunc()
108124

109125
containers := pod.Spec.Containers
@@ -121,5 +137,7 @@ func TestGlobalOperator(t *testing.T) {
121137
}
122138
}
123139
Expect(found).To(BeTrue())
140+
141+
Eventually(Platform(ns)).ShouldNot(BeNil())
124142
})
125143
}

e2e/namespace/install/kustomize/setup_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
. "github.com/onsi/gomega"
3333
)
3434

35-
func TestBasicSetup(t *testing.T) {
35+
func TestSetupBasic(t *testing.T) {
3636
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
3737
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
3838

@@ -43,10 +43,11 @@ func TestBasicSetup(t *testing.T) {
4343
defer Cleanup()
4444

4545
WithNewTestNamespace(t, func(ns string) {
46-
ExecMake(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
46+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
47+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
4748
Eventually(CRDs()).Should(HaveLen(ExpectedCRDs))
4849

49-
ExecMake(t, Make("setup", fmt.Sprintf("NAMESPACE=%s", ns)))
50+
ExpectExecSucceed(t, Make("setup", namespaceArg))
5051

5152
kpRoles := ExpectedKubePromoteRoles
5253
opRoles := kpRoles + ExpectedOSPromoteRoles
@@ -62,7 +63,7 @@ func TestBasicSetup(t *testing.T) {
6263

6364
}
6465

65-
func TestGlobalSetup(t *testing.T) {
66+
func TestSetupGlobal(t *testing.T) {
6667
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
6768
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
6869

@@ -73,10 +74,11 @@ func TestGlobalSetup(t *testing.T) {
7374
defer Cleanup()
7475

7576
WithNewTestNamespace(t, func(ns string) {
76-
ExecMake(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
77+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
78+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
7779
Eventually(CRDs()).Should(HaveLen(ExpectedCRDs))
7880

79-
ExecMake(t, Make("setup", "GLOBAL=true", fmt.Sprintf("NAMESPACE=%s", ns)))
81+
ExpectExecSucceed(t, Make("setup", "GLOBAL=true", namespaceArg))
8082

8183
Eventually(Role(ns)).Should(HaveLen(0))
8284

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//go:build integration
2+
// +build integration
3+
4+
// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
5+
6+
/*
7+
Licensed to the Apache Software Foundation (ASF) under one or more
8+
contributor license agreements. See the NOTICE file distributed with
9+
this work for additional information regarding copyright ownership.
10+
The ASF licenses this file to You under the Apache License, Version 2.0
11+
(the "License"); you may not use this file except in compliance with
12+
the License. You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
*/
22+
23+
package kustomize
24+
25+
import (
26+
"fmt"
27+
"os"
28+
"testing"
29+
30+
. "github.com/apache/camel-k/e2e/support"
31+
testutil "github.com/apache/camel-k/e2e/support/util"
32+
. "github.com/onsi/gomega"
33+
)
34+
35+
func TestUninstallBasic(t *testing.T) {
36+
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
37+
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
38+
39+
// Ensure no CRDs are already installed
40+
UninstallAll()
41+
42+
// Return the cluster to previous state
43+
defer Cleanup()
44+
45+
WithNewTestNamespace(t, func(ns string) {
46+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
47+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
48+
ExpectExecSucceed(t, Make("setup", namespaceArg))
49+
ExpectExecSucceed(t, Make("platform", namespaceArg))
50+
// Skip default kamelets installation for faster test runs
51+
ExpectExecSucceed(t, Make("operator", namespaceArg, "INSTALL_DEFAULT_KAMELETS=false"))
52+
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
53+
54+
// Do uninstall
55+
ExpectExecSucceed(t, Make("uninstall", namespaceArg))
56+
57+
// Refresh the test client to account for the newly installed CRDs
58+
SyncClient()
59+
60+
Eventually(OperatorPod(ns)).Should(BeNil())
61+
Eventually(Platform(ns)).Should(BeNil())
62+
Eventually(Role(ns)).Should(BeNil())
63+
Eventually(ClusterRole()).Should(BeNil())
64+
// CRDs should be still there
65+
Eventually(CRDs()).Should(HaveLen(ExpectedCRDs))
66+
67+
// Do uninstall all
68+
ExpectExecSucceed(t, Make("uninstall", namespaceArg, "UNINSTALL_ALL=true"))
69+
70+
Eventually(CRDs()).Should(BeNil())
71+
})
72+
73+
}
74+
75+
func TestUninstallGlobal(t *testing.T) {
76+
makeDir := testutil.MakeTempCopyDir(t, "../../../../install")
77+
os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir)
78+
79+
// Ensure no CRDs are already installed
80+
UninstallAll()
81+
82+
// Return the cluster to previous state
83+
defer Cleanup()
84+
85+
WithNewTestNamespace(t, func(ns string) {
86+
namespaceArg := fmt.Sprintf("NAMESPACE=%s", ns)
87+
ExpectExecSucceed(t, Make("setup-cluster", namespaceArg))
88+
ExpectExecSucceed(t, Make("setup", namespaceArg, "GLOBAL=true"))
89+
ExpectExecSucceed(t, Make("platform", namespaceArg))
90+
// Skip default kamelets installation for faster test runs
91+
ExpectExecSucceed(t, Make("operator", namespaceArg, "GLOBAL=true", "INSTALL_DEFAULT_KAMELETS=false"))
92+
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
93+
94+
// Do uninstall
95+
ExpectExecSucceed(t, Make("uninstall", namespaceArg))
96+
97+
// Refresh the test client to account for the newly installed CRDs
98+
SyncClient()
99+
100+
Eventually(OperatorPod(ns)).Should(BeNil())
101+
Eventually(Platform(ns)).Should(BeNil())
102+
Eventually(Role(ns)).Should(BeNil())
103+
Eventually(ClusterRole()).Should(BeNil())
104+
// CRDs should be still there
105+
Eventually(CRDs()).Should(HaveLen(ExpectedCRDs))
106+
107+
// Do uninstall all
108+
ExpectExecSucceed(t, Make("uninstall", namespaceArg, "UNINSTALL_ALL=true"))
109+
110+
Eventually(CRDs()).Should(BeNil())
111+
})
112+
}

0 commit comments

Comments
 (0)