Skip to content

Commit

Permalink
Add test case for wego app add --chart (#434)
Browse files Browse the repository at this point in the history
* testing test run on ci

* fix lint problems

* address comment

* add namespace

* Update add_tests.go

* Update add_tests.go

* empty commit

* add another test case and refactor existing one

* clean cluster

* add a test and remove a test

* add more help flag test cases

* reuse existing util functions

* refactor test

* remove focus from tests
  • Loading branch information
rokshana-b committed Jul 9, 2021
1 parent 3ff12b8 commit 312cfe5
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 102 deletions.
68 changes: 38 additions & 30 deletions test/acceptance/test/add_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)

var clusterName string
Expand Down Expand Up @@ -82,24 +84,23 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})

It("SmokeTest - Verify helm repo with app-config-url=NONE can be added to the cluster by running 'wego app add --url=https://charts.kube-ops.io --chart=loki --app-config-url=NONE' ", func() {
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
addCommand := "app add --url=https://charts.kube-ops.io --chart=loki --app-config-url=NONE"
appName := "loki"
workloadName := "loki-0"
workloadNamespace := WEGO_DEFAULT_NAMESPACE
helmRepoURL := "https://charts.kube-ops.io"
addCommand := "app add --url=" + helmRepoURL + " --chart=" + appName + " --app-config-url=NONE"

defer uninstallWego()

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

By("And I install wego to my active cluster", func() {
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
})

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

By("And I run wego add command", func() {
Expand All @@ -108,7 +109,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {

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

Expand Down Expand Up @@ -288,7 +289,6 @@ var _ = Describe("Weave GitOps Add Tests", func() {
private := true
appManifestFilePath := "./data/helm-repo/hello-world"
configRepoFiles := "./data/config-repo"
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
appName := "my-helm-app"
appRepoName := "wego-test-app-" + RandString(8)
configRepoName := "wego-test-config-repo-" + RandString(8)
Expand Down Expand Up @@ -318,8 +318,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
})

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

By("And I run wego add command", func() {
Expand Down Expand Up @@ -353,7 +353,6 @@ var _ = Describe("Weave GitOps Add Tests", func() {
var repoAbsolutePath string
private := true
appManifestFilePath := "./data/helm-repo/hello-world"
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
appName := "my-helm-app"
appRepoName := "wego-test-app-" + RandString(8)
addCommand := fmt.Sprintf("app add . --app-config-url=NONE --deployment-type=helm --path=./hello-world --name=%s", appName)
Expand All @@ -373,8 +372,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
installAndVerifyWego(WEGO_DEFAULT_NAMESPACE)
})

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

By("And I run wego add command", func() {
Expand Down Expand Up @@ -433,8 +432,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
tip := generateTestInputs()
branchName := "test-branch-01"

url := "ssh://git@github.com/" + GITHUB_ORG + "/" + tip.appRepoName + ".git"
addCommand := "app add --url=" + url + " --branch=" + branchName + " --dry-run" + " --auto-merge=true"
appRepoRemoteURL := "ssh://git@github.com/" + GITHUB_ORG + "/" + tip.appRepoName + ".git"
addCommand := "app add --url=" + appRepoRemoteURL + " --branch=" + branchName + " --dry-run" + " --auto-merge=true"
appName := tip.appRepoName
appType := "Kustomization"

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

By("Then I should see dry-run output with specified: url, namespace, branch", func() {
Eventually(addCommandOutput).Should(MatchRegexp(`using URL: '` + url + `'`))
Eventually(addCommandOutput).Should(MatchRegexp(`using URL: '` + appRepoRemoteURL + `'`))
Eventually(addCommandOutput).Should(MatchRegexp(`Checking cluster status... WeGOInstalled`))

Eventually(addCommandOutput).Should(MatchRegexp(
Expand All @@ -480,11 +479,10 @@ var _ = Describe("Weave GitOps Add Tests", func() {
Eventually(addCommandOutput).Should(MatchRegexp(`Applying manifests to the cluster...`))

Eventually(addCommandOutput).Should(MatchRegexp(
`apiVersion:.*\nkind: GitRepository\nmetadata:\n\s*name: ` + appName + `\n\s*namespace: ` + WEGO_DEFAULT_NAMESPACE + `[a-z0-9:\n\s*]+branch: ` + branchName + `[a-zA-Z0-9:\n\s*-]+url: ` + url))
`apiVersion:.*\nkind: GitRepository\nmetadata:\n\s*name: ` + appName + `\n\s*namespace: ` + WEGO_DEFAULT_NAMESPACE + `[a-z0-9:\n\s*]+branch: ` + branchName + `[a-zA-Z0-9:\n\s*-]+url: ` + appRepoRemoteURL))

Eventually(addCommandOutput).Should(MatchRegexp(
`apiVersion:.*\nkind: ` + appType + `\nmetadata:\n\s*name: ` + appName + `-wego-apps-dir\n\s*namespace: ` + WEGO_DEFAULT_NAMESPACE))

})

By("And I should not see any workload deployed to the cluster", func() {
Expand All @@ -500,8 +498,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
branchName := "test-branch-02"

wegoNamespace := "my-space"
url := "ssh://git@github.com/" + GITHUB_ORG + "/" + tip.appRepoName + ".git"
addCommand := "app add --url=" + url + " --branch=" + branchName + " --namespace=" + wegoNamespace + " --auto-merge=true"
appRepoRemoteURL := "ssh://git@github.com/" + GITHUB_ORG + "/" + tip.appRepoName + ".git"
addCommand := "app add --url=" + appRepoRemoteURL + " --branch=" + branchName + " --namespace=" + wegoNamespace + " --auto-merge=true"
appName := tip.appRepoName

defer deleteRepo(tip.appRepoName)
Expand Down Expand Up @@ -547,7 +545,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})

By("And my app is deployed under specified branch name", func() {
branchOutput, _ := runCommandAndReturnOutput(fmt.Sprintf("kubectl get -n %s GitRepositories", wegoNamespace))
branchOutput, _ := runCommandAndReturnStringOutput(fmt.Sprintf("kubectl get -n %s GitRepositories", wegoNamespace))
Eventually(branchOutput).Should(ContainSubstring(appName))
Eventually(branchOutput).Should(ContainSubstring(branchName))
})
Expand Down Expand Up @@ -626,8 +624,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})

By("When I create a private repo for wego app config", func() {
appCofigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appCofigRepoAbsPath, tip.appManifestFilePath)
appConfigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appConfigRepoAbsPath, tip.appManifestFilePath)
})

By("When I create a private repo with my app workload", func() {
Expand Down Expand Up @@ -679,8 +677,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})

By("When I create a private repo for wego app config", func() {
appCofigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appCofigRepoAbsPath, tip.appManifestFilePath)
appConfigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appConfigRepoAbsPath, tip.appManifestFilePath)
})

By("When I create a private repo with my app workload", func() {
Expand Down Expand Up @@ -844,8 +842,8 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})

By("When I create a private repo for wego app config", func() {
appCofigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appCofigRepoAbsPath, readmeFilePath)
appConfigRepoAbsPath := initAndCreateEmptyRepo(appConfigRepoName, private)
gitAddCommitPush(appConfigRepoAbsPath, readmeFilePath)
})

By("And I create a repo with my app1 workload and run the add the command on it", func() {
Expand Down Expand Up @@ -919,8 +917,9 @@ var _ = Describe("Weave GitOps Add Tests", func() {
})
})

It("Verify wego can add kustomize-based app with 'app-config-url=NONE'", func() {
It("SmokeTest - Verify wego can add kustomize-based app with 'app-config-url=NONE'", func() {
var repoAbsolutePath string
var statusOutput *gexec.Session
private := true
tip := generateTestInputs()
DEFAULT_SSH_KEY_PATH := "~/.ssh/id_rsa"
Expand Down Expand Up @@ -962,11 +961,20 @@ var _ = Describe("Weave GitOps Add Tests", func() {

By("And I should not see wego components in the remote git repo", func() {
pullGitRepo(repoAbsolutePath)
folderOutput, _ := runCommandAndReturnOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
folderOutput, _ := runCommandAndReturnStringOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
Expect(folderOutput).ShouldNot(ContainSubstring(".wego"))
Expect(folderOutput).ShouldNot(ContainSubstring("apps"))
Expect(folderOutput).ShouldNot(ContainSubstring("targets"))
})

By("When I run wego app status", func() {
statusOutput = runCommandAndReturnSessionOutput(fmt.Sprintf("%s app status %s", WEGO_BIN_PATH, appName))
})

By("Then I can see app status", func() {
Eventually(statusOutput).Should(gbytes.Say(
`Latest successful deployment time: 202[0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z\n.*\n.*gitrepository\/` + appName + `\s*True\s*Fetched revision: main\/.{40}\smain\/.{40}\s*False\s*\n.*\n.*kustomization\/` + appName + `\s*True\s*Applied revision: main\/.{40}\smain\/.{40}\s*False`))
})
})

It("Verify wego can add kustomize-based app with 'app-config-url=NONE' and a URL", func() {
Expand Down Expand Up @@ -1012,7 +1020,7 @@ var _ = Describe("Weave GitOps Add Tests", func() {

By("And I should not see wego components in the remote git repo", func() {
pullGitRepo(repoAbsolutePath)
folderOutput, _ := runCommandAndReturnOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
folderOutput, _ := runCommandAndReturnStringOutput(fmt.Sprintf("cd %s && ls -al", repoAbsolutePath))
Expect(folderOutput).ShouldNot(ContainSubstring(".wego"))
Expect(folderOutput).ShouldNot(ContainSubstring("apps"))
Expect(folderOutput).ShouldNot(ContainSubstring("targets"))
Expand Down
23 changes: 14 additions & 9 deletions test/acceptance/test/flux_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
package acceptance

import (
"os/exec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

var _ = Describe("WEGO Flux Tests", func() {

var session *gexec.Session
var err error
var sessionOutput *gexec.Session

BeforeEach(func() {

Expand All @@ -27,14 +24,22 @@ var _ = Describe("WEGO Flux Tests", func() {
It("Verify that wego-flux displays error message when provided with the wrong flag", func() {

By("When I run the command 'wego flux foo'", func() {
command := exec.Command(WEGO_BIN_PATH, "flux", "foo")
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())

sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " flux foo")
})

By("Then I should see wego error message", func() {
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("✗ unknown command \"foo\" for \"flux\""))
Eventually(sessionOutput.Wait().Out.Contents()).Should(ContainSubstring("✗ unknown command \"foo\" for \"flux\""))
})
})

It("Verify that wego-flux can print out the version of flux", func() {

By("When I run the command 'wego flux -v'", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " flux -v")
})

By("Then I should see flux version", func() {
Eventually(sessionOutput.Wait().Out.Contents()).Should(MatchRegexp(`flux version 0.[0-9][0-9].[0-9]\d*`))
})
})
})
76 changes: 43 additions & 33 deletions test/acceptance/test/help_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var _ = Describe("WEGO Help Tests", func() {

var session *gexec.Session
var sessionOutput *gexec.Session
var err error

BeforeEach(func() {
Expand All @@ -25,63 +25,73 @@ var _ = Describe("WEGO Help Tests", func() {

By("When I run 'wego foo'", func() {
command := exec.Command(WEGO_BIN_PATH, "foo")
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
sessionOutput, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
})

By("Then I should see wego error message", func() {
Eventually(session.Err).Should(gbytes.Say("Error: unknown command \"foo\" for \"wego\""))
Eventually(session.Err).Should(gbytes.Say("Run 'wego --help' for usage."))
Eventually(sessionOutput.Err).Should(gbytes.Say("Error: unknown command \"foo\" for \"wego\""))
Eventually(sessionOutput.Err).Should(gbytes.Say("Run 'wego --help' for usage."))
})
})

VerifyUsageText := func() {
It("Verify that wego help flag prints the help text", func() {

By("Then I should see help message printed with the product name", func() {
Eventually(session).Should(gbytes.Say("Weave GitOps"))
By("When I run the command 'wego --help' ", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " --help")
})

By("And Usage category", func() {
Eventually(session).Should(gbytes.Say("Usage:"))
Eventually(string(session.Wait().Out.Contents())).Should(ContainSubstring("wego [command]"))
By("Then I should see help message printed for wego", func() {
Eventually(string(sessionOutput.Wait().Out.Contents())).Should(MatchRegexp(
`Weave GitOps\n*Usage:\n\s*wego \[command]\n*Available Commands:\n\s*app\s*\n\s*flux\s*Use flux commands\n\s*gitops\s*Manages your wego installation\n\s*help\s*Help about any command\n\s*version\s*Display wego version\n*Flags:\n\s*-h, --help\s*help for wego\n\s*--namespace string\s*gitops runtime namespace \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output\n*Use "wego \[command] --help" for more information about a command.`))
})
})

It("Verify that wego app help flag prints the help text", func() {

By("And Avalaible-Commands category", func() {
Eventually(session).Should(gbytes.Say("Available Commands:"))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`flux[\s]+Use flux commands`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`help[\s]+Help about any command`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`version[\s]+Display wego version`))
By("When I run the command 'wego app -h' ", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " app -h")
})

By("And Flags category", func() {
Eventually(session).Should(gbytes.Say("Flags:"))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-h, --help[\s]+help for wego`))
Eventually(string(session.Wait().Out.Contents())).Should(MatchRegexp(`-v, --verbose[\s]+Enable verbose output`))
By("Then I should see help message printed for wego app", func() {
Eventually(string(sessionOutput.Wait().Out.Contents())).Should(MatchRegexp(
`Usage:\n\s*wego app \[command]\n*Available Commands:\n\s*add\s*Add a workload repository to a wego cluster\n\s*list\s*List applications\n\s*status\s*Get status of an app\n*Flags:\n\s*-h, --help\s*help for app\n*Global Flags:\n\s*--namespace string\s*gitops runtime namespace \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output\n*Use "wego app \[command] --help" for more information about a command.`))
})
})

}
It("Verify that wego app add help flag prints the help text", func() {

It("Verify that wego help flag prints the help text", func() {
By("When I run the command 'wego app add -h' ", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " app add -h")
})

By("When I run the command 'wego --help' ", func() {
command := exec.Command(WEGO_BIN_PATH, "--help")
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
By("Then I should see help message printed for wego app add", func() {
Eventually(string(sessionOutput.Wait().Out.Contents())).Should(MatchRegexp(
`Associates an additional application in a git repository with a wego cluster so that its contents may be managed via GitOps\n*Usage:\n\s*wego app add \[--name <name>] \[--url <url>] \[--branch <branch>] \[--path <path within repository>] \[--private-key <keyfile>] <repository directory> \[flags]\n*Examples:\nwego app add .\n*Flags:\n\s*--app-config-url string\s*URL of external repository \(if any\) which will hold automation manifests; NONE to store only in the cluster\n\s*--auto-merge\s*If set, 'wego add' will merge automatically into the set --branch\n\s*--branch string\s*Branch to watch within git repository \(default "main"\)\n\s*--chart string\s*Specify chart for helm source\n\s*--deployment-type string\s*deployment type \[kustomize, helm] \(default "kustomize"\)\n\s*--dry-run\s*If set, 'wego add' will not make any changes to the system; it will just display the actions that would have been taken\n\s*-h, --help\s*help for add\n\s*--name string\s*Name of remote git repository\n\s*--path string\s*Path of files within git repository \(default "\.\/"\)\n\s*--private-key string\s*Private key to access git repository over ssh\n\s*--url string\s*URL of remote repository\n*Global Flags:\n\s*--namespace string\s*gitops runtime namespace \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output`))
})
})

VerifyUsageText()
It("Verify that wego app status help flag prints the help text", func() {

By("When I run the command 'wego app add -h' ", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " app status -h")
})

By("Then I should see help message printed for wego app status", func() {
Eventually(string(sessionOutput.Wait().Out.Contents())).Should(MatchRegexp(
`Get status of an app\n*Usage:\n\s*wego app status <app-name> \[flags]\n*Examples:\nwego app status podinfo\n*Flags:\n\s*-h, --help\s*help for status\n*\s*Global Flags:\n\s*--namespace string\s*gitops runtime namespace \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output`))
})
})

It("Verify that wego command prints the help text", func() {
It("Verify that wego app list help flag prints the help text", func() {

By("When I run the command 'wego'", func() {
command := exec.Command(WEGO_BIN_PATH)
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
By("When I run the command 'wego app list -h' ", func() {
sessionOutput = runCommandAndReturnSessionOutput(WEGO_BIN_PATH + " app list -h")
})

VerifyUsageText()

By("Then I should see help message printed for wego app list", func() {
Eventually(string(sessionOutput.Wait().Out.Contents())).Should(MatchRegexp(
`List applications\n*Usage:\n\s*wego app list \[flags]\n*Examples:\nwego app list\n*Flags:\n\s*-h, --help\s*help for list\n*\s*Global Flags:\n\s*--namespace string\s*gitops runtime namespace \(default "wego-system"\)\n\s*-v, --verbose\s*Enable verbose output`))
})
})
})

0 comments on commit 312cfe5

Please sign in to comment.