Skip to content

Commit ca78d97

Browse files
authored
add wego-uninstall & app-config=none tests (#413)
* add wego-uninstall & app-config=none tests * fix lint issues * run tests on ci * run install tests on ci * remove smoke tags * change test placement
1 parent 79722a5 commit ca78d97

File tree

3 files changed

+85
-37
lines changed

3 files changed

+85
-37
lines changed

test/acceptance/test/add_tests.go

+58-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
309309
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
310310
appRepoName := "wego-test-app-" + RandString(8)
311311
url := "ssh://[email protected]/" + os.Getenv("GITHUB_ORG") + "/" + appRepoName + ".git"
312-
addCommand := "app add . --url=" + url + " --branch=" + branchName + " --dry-run"
312+
addCommand := "app add --url=" + url + " --branch=" + branchName + " --dry-run"
313313
appName := appRepoName
314314
appType := "Kustomization"
315315

@@ -365,7 +365,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
365365
})
366366

367367
// Eventually this test run will include all the remaining un-automated `wego app add` flags.
368-
It("Verify 'wego app add' works with user-specified branch, namespace", func() {
368+
It("Verify 'wego app add' works with user-specified branch, namespace, url", func() {
369369
var repoAbsolutePath string
370370
private := true
371371
appRepoName := "wego-test-app-" + RandString(8)
@@ -376,7 +376,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
376376
workloadNamespace := "my-nginx-" + uniqueSuffix
377377
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
378378
wegoNamespace := "my-space"
379-
addCommand := "app add . --branch=" + branchName + " --namespace=" + wegoNamespace
379+
url := "ssh://[email protected]/" + os.Getenv("GITHUB_ORG") + "/" + appRepoName + ".git"
380+
addCommand := "app add --url=" + url + " --branch=" + branchName + " --namespace=" + wegoNamespace
380381
appName := appRepoName
381382

382383
defer deleteRepo(appRepoName)
@@ -412,7 +413,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
412413
createGitRepoBranch(repoAbsolutePath, branchName)
413414
})
414415

415-
By("And I run wego add command with specified branch", func() {
416+
By("And I run wego add command with specified branch, namespace, url", func() {
416417
runWegoAddCommand(repoAbsolutePath, addCommand, wegoNamespace)
417418
})
418419

@@ -827,4 +828,57 @@ var _ = Describe("Weave GitOps Add Tests", func() {
827828
verifyWorkloadIsDeployed(workloadName2, workloadNamespace2)
828829
})
829830
})
831+
832+
It("Verify wego can add kustomize-based app with 'app-config-url=NONE'", func() {
833+
var repoAbsolutePath string
834+
private := true
835+
appRepoName := "wego-test-app-" + RandString(8)
836+
uniqueSuffix := RandString(6)
837+
appManifestFilePath := getUniqueWorkload("xxyyzz", uniqueSuffix)
838+
workloadName := "nginx-" + uniqueSuffix
839+
workloadNamespace := "my-nginx-" + uniqueSuffix
840+
defaultSshKeyPath := "~/.ssh/id_rsa"
841+
addCommand := "app add . --app-config-url=NONE"
842+
appName := appRepoName
843+
844+
defer deleteRepo(appRepoName)
845+
defer deleteWorkload(workloadName, workloadNamespace)
846+
847+
By("And application repo does not already exist", func() {
848+
deleteRepo(appRepoName)
849+
})
850+
851+
By("And application workload is not already deployed to cluster", func() {
852+
deleteWorkload(workloadName, workloadNamespace)
853+
})
854+
855+
By("When I create a private repo with my app workload", func() {
856+
repoAbsolutePath = initAndCreateEmptyRepo(appRepoName, private)
857+
gitAddCommitPush(repoAbsolutePath, appManifestFilePath)
858+
})
859+
860+
By("And I install wego under my namespace: "+WEGO_DEFAULT_NAMESPACE, func() {
861+
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
862+
})
863+
864+
By("And I have my default ssh key on path "+defaultSshKeyPath, func() {
865+
setupSSHKey(defaultSshKeyPath)
866+
})
867+
868+
By("And I run wego add command with app-config-url set to 'none'", func() {
869+
runWegoAddCommand(repoAbsolutePath, addCommand, WEGO_DEFAULT_NAMESPACE)
870+
})
871+
872+
By("Then I should see my workload deployed to the cluster", func() {
873+
verifyWegoAddCommand(appName, WEGO_DEFAULT_NAMESPACE)
874+
verifyWorkloadIsDeployed(workloadName, workloadNamespace)
875+
})
876+
877+
By("And I should not see wego components in the remote git repo", func() {
878+
folderOutput, _ := runCommandAndReturnOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
879+
Eventually(folderOutput).ShouldNot(ContainSubstring(".wego"))
880+
Eventually(folderOutput).ShouldNot(ContainSubstring("apps"))
881+
Eventually(folderOutput).ShouldNot(ContainSubstring("targets"))
882+
})
883+
})
830884
})

test/acceptance/test/install_tests.go

+25-31
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ var _ = Describe("Weave GitOps Install Tests", func() {
2222
})
2323

2424
It("Validate that wego displays help text for 'install' command", func() {
25+
2526
var session *gexec.Session
2627
var err error
28+
2729
By("When I run the command 'wego gitops install -h'", func() {
2830
command := exec.Command(WEGO_BIN_PATH, "gitops", "install", "-h")
2931
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
@@ -32,39 +34,36 @@ var _ = Describe("Weave GitOps Install Tests", func() {
3234
})
3335

3436
By("Then I should see wego help text displayed for 'install' command", func() {
35-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`The install command deploys Wego in the specified namespace.`))
36-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`If a previous version is installed, then an in-place upgrade will be performed.`))
37-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Usage:`))
38-
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("wego gitops install [flags]"))
39-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Examples:`))
40-
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("# Install wego in the wego-system namespace"))
41-
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("wego gitops install"))
42-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Flags:`))
43-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-h, --help[\s]+help for install`))
44-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Global Flags`))
45-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`--namespace string[\s]+the namespace scope for this operation \(default "wego-system"\)`))
46-
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-v, --verbose[\s]+Enable verbose output`))
37+
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(
38+
`The install command deploys Wego in the specified namespace.\nIf a previous version is installed, then an in-place upgrade will be performed.\n*Usage:\n\s*wego gitops install \[flags]\n*Examples:\n\s*# Install wego in the wego-system namespace\n\s*wego gitops install\n*Flags:\n\s*-h, --help\s*help for install\n*Global Flags:\n\s*--dry-run\s*outputs all the manifests that would be installed\n\s*-n, --namespace string\s*the namespace scope for this operation \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output`))
4739
})
4840
})
4941

50-
It("Verify that wego can install required controllers under default namespace `wego-system`", func() {
42+
It("Verify that wego can install & uninstall wego components under default namespace `wego-system`", func() {
5143

5244
By("And I have a brand new cluster", func() {
5345
_, err := ResetOrCreateCluster(WEGO_DEFAULT_NAMESPACE, true)
5446
Expect(err).ShouldNot(HaveOccurred())
5547
})
5648

57-
By("When I run 'wego install' command with default namespace", func() {
58-
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops install", WEGO_BIN_PATH))
49+
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
50+
51+
By("When I run 'wego gitops uninstall' command", func() {
52+
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops uninstall --namespace %s", WEGO_BIN_PATH, WEGO_DEFAULT_NAMESPACE))
5953
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
6054
Expect(err).ShouldNot(HaveOccurred())
61-
Eventually(session, TIMEOUT_TWO_SECONDS).Should(gexec.Exit())
55+
Eventually(session).Should(gexec.Exit())
6256
})
6357

64-
VerifyControllersInCluster(WEGO_DEFAULT_NAMESPACE)
58+
_ = waitForNamespaceToTerminate(WEGO_DEFAULT_NAMESPACE, NAMESPACE_TERMINATE_TIMEOUT)
59+
60+
By("Then I should not see any wego components", func() {
61+
_, errOutput := runCommandAndReturnOutput("kubectl get ns " + WEGO_DEFAULT_NAMESPACE)
62+
Eventually(errOutput).Should(ContainSubstring(`Error from server (NotFound): namespaces "` + WEGO_DEFAULT_NAMESPACE + `" not found`))
63+
})
6564
})
6665

67-
It("Verify that wego can add flux controllers to a user-specified namespace", func() {
66+
It("Verify that wego can install & uninstall wego components under a user-specified namespace", func() {
6867

6968
namespace := "test-namespace"
7069

@@ -73,25 +72,20 @@ var _ = Describe("Weave GitOps Install Tests", func() {
7372
Expect(err).ShouldNot(HaveOccurred())
7473
})
7574

76-
By("And I create a namespace for my controllers", func() {
77-
command := exec.Command("kubectl", "create", "namespace", namespace)
78-
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
79-
Expect(err).ShouldNot(HaveOccurred())
80-
Eventually(session).Should(gexec.Exit())
81-
})
75+
installAndVerifyWego(namespace)
8276

83-
By("When I run 'wego install' command with specified namespace", func() {
84-
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops install --namespace %s", WEGO_BIN_PATH, namespace))
77+
By("When I run 'wego gitops uninstall' command", func() {
78+
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops uninstall --namespace %s", WEGO_BIN_PATH, namespace))
8579
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
8680
Expect(err).ShouldNot(HaveOccurred())
87-
Eventually(session, TIMEOUT_TWO_SECONDS).Should(gexec.Exit())
81+
Eventually(session).Should(gexec.Exit())
8882
})
8983

90-
VerifyControllersInCluster(namespace)
84+
_ = waitForNamespaceToTerminate(namespace, NAMESPACE_TERMINATE_TIMEOUT)
9185

92-
By("Clean up the namespace", func() {
93-
_, err := ResetOrCreateCluster(namespace, true)
94-
Expect(err).ShouldNot(HaveOccurred())
86+
By("Then I should not see any wego components", func() {
87+
_, errOutput := runCommandAndReturnOutput("kubectl get ns " + namespace)
88+
Eventually(errOutput).Should(ContainSubstring(`Error from server (NotFound): namespaces "` + namespace + `" not found`))
9589
})
9690
})
9791
})

test/acceptance/test/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
const EVENTUALLY_DEFAULT_TIME_OUT time.Duration = 60 * time.Second
22-
const TIMEOUT_TWO_SECONDS time.Duration = 120 * time.Second
22+
const TIMEOUT_TWO_MINUTES time.Duration = 120 * time.Second
2323
const INSTALL_RESET_TIMEOUT time.Duration = 300 * time.Second
2424
const NAMESPACE_TERMINATE_TIMEOUT time.Duration = 600 * time.Second
2525
const INSTALL_PODS_READY_TIMEOUT time.Duration = 180 * time.Second
@@ -333,7 +333,7 @@ func installAndVerifyWego(wegoNamespace string) {
333333
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops install --namespace=%s", WEGO_BIN_PATH, wegoNamespace))
334334
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
335335
Expect(err).ShouldNot(HaveOccurred())
336-
Eventually(session, TIMEOUT_TWO_SECONDS).Should(gexec.Exit())
336+
Eventually(session, TIMEOUT_TWO_MINUTES).Should(gexec.Exit())
337337
VerifyControllersInCluster(wegoNamespace)
338338
})
339339
}

0 commit comments

Comments
 (0)