Skip to content

Commit

Permalink
add wego-uninstall & app-config=none tests (weaveworks#413)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rokshana-b authored Jun 30, 2021
1 parent 79722a5 commit ca78d97
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 37 deletions.
62 changes: 58 additions & 4 deletions test/acceptance/test/add_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
appRepoName := "wego-test-app-" + RandString(8)
url := "ssh://[email protected]/" + os.Getenv("GITHUB_ORG") + "/" + appRepoName + ".git"
addCommand := "app add . --url=" + url + " --branch=" + branchName + " --dry-run"
addCommand := "app add --url=" + url + " --branch=" + branchName + " --dry-run"
appName := appRepoName
appType := "Kustomization"

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

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

defer deleteRepo(appRepoName)
Expand Down Expand Up @@ -412,7 +413,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
createGitRepoBranch(repoAbsolutePath, branchName)
})

By("And I run wego add command with specified branch", func() {
By("And I run wego add command with specified branch, namespace, url", func() {
runWegoAddCommand(repoAbsolutePath, addCommand, wegoNamespace)
})

Expand Down Expand Up @@ -827,4 +828,57 @@ var _ = Describe("Weave GitOps Add Tests", func() {
verifyWorkloadIsDeployed(workloadName2, workloadNamespace2)
})
})

It("Verify wego can add kustomize-based app with 'app-config-url=NONE'", func() {
var repoAbsolutePath string
private := true
appRepoName := "wego-test-app-" + RandString(8)
uniqueSuffix := RandString(6)
appManifestFilePath := getUniqueWorkload("xxyyzz", uniqueSuffix)
workloadName := "nginx-" + uniqueSuffix
workloadNamespace := "my-nginx-" + uniqueSuffix
defaultSshKeyPath := "~/.ssh/id_rsa"
addCommand := "app add . --app-config-url=NONE"
appName := appRepoName

defer deleteRepo(appRepoName)
defer deleteWorkload(workloadName, workloadNamespace)

By("And application repo does not already exist", func() {
deleteRepo(appRepoName)
})

By("And application workload is not already deployed to cluster", func() {
deleteWorkload(workloadName, workloadNamespace)
})

By("When I create a private repo with my app workload", func() {
repoAbsolutePath = initAndCreateEmptyRepo(appRepoName, private)
gitAddCommitPush(repoAbsolutePath, appManifestFilePath)
})

By("And I install wego under my namespace: "+WEGO_DEFAULT_NAMESPACE, func() {
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
})

By("And I have my default ssh key on path "+defaultSshKeyPath, func() {
setupSSHKey(defaultSshKeyPath)
})

By("And I run wego add command with app-config-url set to 'none'", func() {
runWegoAddCommand(repoAbsolutePath, addCommand, WEGO_DEFAULT_NAMESPACE)
})

By("Then I should see my workload deployed to the cluster", func() {
verifyWegoAddCommand(appName, WEGO_DEFAULT_NAMESPACE)
verifyWorkloadIsDeployed(workloadName, workloadNamespace)
})

By("And I should not see wego components in the remote git repo", func() {
folderOutput, _ := runCommandAndReturnOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
Eventually(folderOutput).ShouldNot(ContainSubstring(".wego"))
Eventually(folderOutput).ShouldNot(ContainSubstring("apps"))
Eventually(folderOutput).ShouldNot(ContainSubstring("targets"))
})
})
})
56 changes: 25 additions & 31 deletions test/acceptance/test/install_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ var _ = Describe("Weave GitOps Install Tests", func() {
})

It("Validate that wego displays help text for 'install' command", func() {

var session *gexec.Session
var err error

By("When I run the command 'wego gitops install -h'", func() {
command := exec.Command(WEGO_BIN_PATH, "gitops", "install", "-h")
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expand All @@ -32,39 +34,36 @@ var _ = Describe("Weave GitOps Install Tests", func() {
})

By("Then I should see wego help text displayed for 'install' command", func() {
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`The install command deploys Wego in the specified namespace.`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`If a previous version is installed, then an in-place upgrade will be performed.`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Usage:`))
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("wego gitops install [flags]"))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Examples:`))
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("# Install wego in the wego-system namespace"))
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("wego gitops install"))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Flags:`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-h, --help[\s]+help for install`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`Global Flags`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`--namespace string[\s]+the namespace scope for this operation \(default "wego-system"\)`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-v, --verbose[\s]+Enable verbose output`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(
`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`))
})
})

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

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

By("When I run 'wego install' command with default namespace", func() {
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops install", WEGO_BIN_PATH))
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)

By("When I run 'wego gitops uninstall' command", func() {
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops uninstall --namespace %s", WEGO_BIN_PATH, WEGO_DEFAULT_NAMESPACE))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session, TIMEOUT_TWO_SECONDS).Should(gexec.Exit())
Eventually(session).Should(gexec.Exit())
})

VerifyControllersInCluster(WEGO_DEFAULT_NAMESPACE)
_ = waitForNamespaceToTerminate(WEGO_DEFAULT_NAMESPACE, NAMESPACE_TERMINATE_TIMEOUT)

By("Then I should not see any wego components", func() {
_, errOutput := runCommandAndReturnOutput("kubectl get ns " + WEGO_DEFAULT_NAMESPACE)
Eventually(errOutput).Should(ContainSubstring(`Error from server (NotFound): namespaces "` + WEGO_DEFAULT_NAMESPACE + `" not found`))
})
})

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

namespace := "test-namespace"

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

By("And I create a namespace for my controllers", func() {
command := exec.Command("kubectl", "create", "namespace", namespace)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session).Should(gexec.Exit())
})
installAndVerifyWego(namespace)

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

VerifyControllersInCluster(namespace)
_ = waitForNamespaceToTerminate(namespace, NAMESPACE_TERMINATE_TIMEOUT)

By("Clean up the namespace", func() {
_, err := ResetOrCreateCluster(namespace, true)
Expect(err).ShouldNot(HaveOccurred())
By("Then I should not see any wego components", func() {
_, errOutput := runCommandAndReturnOutput("kubectl get ns " + namespace)
Eventually(errOutput).Should(ContainSubstring(`Error from server (NotFound): namespaces "` + namespace + `" not found`))
})
})
})
4 changes: 2 additions & 2 deletions test/acceptance/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const EVENTUALLY_DEFAULT_TIME_OUT time.Duration = 60 * time.Second
const TIMEOUT_TWO_SECONDS time.Duration = 120 * time.Second
const TIMEOUT_TWO_MINUTES time.Duration = 120 * time.Second
const INSTALL_RESET_TIMEOUT time.Duration = 300 * time.Second
const NAMESPACE_TERMINATE_TIMEOUT time.Duration = 600 * time.Second
const INSTALL_PODS_READY_TIMEOUT time.Duration = 180 * time.Second
Expand Down Expand Up @@ -333,7 +333,7 @@ func installAndVerifyWego(wegoNamespace string) {
command := exec.Command("sh", "-c", fmt.Sprintf("%s gitops install --namespace=%s", WEGO_BIN_PATH, wegoNamespace))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session, TIMEOUT_TWO_SECONDS).Should(gexec.Exit())
Eventually(session, TIMEOUT_TWO_MINUTES).Should(gexec.Exit())
VerifyControllersInCluster(wegoNamespace)
})
}
Expand Down

0 comments on commit ca78d97

Please sign in to comment.