Skip to content

Commit

Permalink
Replaced multiple expect check within same variable with MatchAllInOu…
Browse files Browse the repository at this point in the history
…tput and DontMatchAllInOutput throughout the test
  • Loading branch information
prietyc123 committed May 27, 2020
1 parent 698512c commit 7cb1695
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 115 deletions.
13 changes: 4 additions & 9 deletions tests/e2escenarios/e2e_beta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,14 @@ var _ = Describe("odo core beta flow", func() {
helper.CmdShouldPass(odo, append([]string{"push"}, extraArgs...)...)

dcSession := oc.GetComponentDC("mycomponent", "myapp", project)
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/instance: mycomponent"))
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/component-source-type: local"))
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/name: java"))
Expect(dcSession).Should(ContainSubstring("app.kubernetes.io/part-of: myapp"))
Expect(dcSession).Should(ContainSubstring("name: mycomponent-myapp"))
helper.MatchAllInOutput(dcSession, []string{"app.kubernetes.io/instance: mycomponent", "app.kubernetes.io/component-source-type: local", "app.kubernetes.io/name: java", "app.kubernetes.io/part-of: myapp", "name: mycomponent-myapp"})

// DC should have env variable
Expect(dcSession).Should(ContainSubstring("name: FOO"))
Expect(dcSession).Should(ContainSubstring("value: bar"))
helper.MatchAllInOutput(dcSession, []string{"name: FOO", "value: bar"})

routeSession := oc.GetComponentRoutes("mycomponent", "myapp", project)
// check that route is pointing gto right port and component
Expect(routeSession).Should(ContainSubstring("targetPort: 8080"))
Expect(routeSession).Should(ContainSubstring("name: mycomponent-myapp"))
helper.MatchAllInOutput(routeSession, []string{"targetPort: 8080", "name: mycomponent-myapp"})
url := oc.GetFirstURL("mycomponent", "myapp", project)
helper.HttpWaitFor("http://"+url, "Hello World from Javalin!", 10, 5)
}
Expand Down
11 changes: 3 additions & 8 deletions tests/integration/cmd_pref_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ var _ = Describe("odo preference and config command tests", func() {
})
It("should get the default global config keys", func() {
configOutput := helper.CmdShouldPass("odo", "preference", "view")
Expect(configOutput).To(ContainSubstring("UpdateNotification"))
Expect(configOutput).To(ContainSubstring("NamePrefix"))
Expect(configOutput).To(ContainSubstring("Timeout"))
Expect(configOutput).To(ContainSubstring("PushTarget"))
helper.MatchAllInOutput(configOutput, []string{"configOutput", "NamePrefix", "Timeout", "PushTarget"})
updateNotificationValue := helper.GetPreferenceValue("UpdateNotification")
Expect(updateNotificationValue).To(BeEmpty())
namePrefixValue := helper.GetPreferenceValue("NamePrefix")
Expand Down Expand Up @@ -289,8 +286,7 @@ var _ = Describe("odo preference and config command tests", func() {
helper.CmdShouldPass("odo", "config", "unset", "--env", "PORT", "--context", context)
helper.CmdShouldPass("odo", "config", "unset", "--env", "SECRET_KEY", "--context", context)
configValue := helper.CmdShouldPass("odo", "config", "view", "--context", context)
Expect(configValue).To(Not(ContainSubstring(("PORT"))))
Expect(configValue).To(Not(ContainSubstring(("SECRET_KEY"))))
helper.DontMatchAllInOutput(configValue, []string{"PORT", "SECRET_KEY"})
})
It("should check for existence of environment variable in config before unsetting it", func() {
helper.CmdShouldPass("odo", "create", "nodejs", "--project", project, "--context", context)
Expand Down Expand Up @@ -322,8 +318,7 @@ var _ = Describe("odo preference and config command tests", func() {
kubeconfigOld := os.Getenv("KUBECONFIG")
os.Setenv("KUBECONFIG", "/no/such/path")
configValue := helper.CmdShouldPass("odo", "config", "view", "--context", context)
Expect(configValue).To(ContainSubstring("hello"))
Expect(configValue).To(ContainSubstring("world"))
helper.MatchAllInOutput(configValue, []string{"hello", "world"})
os.Setenv("KUBECONFIG", kubeconfigOld)
})

Expand Down
6 changes: 2 additions & 4 deletions tests/integration/cmd_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ var _ = Describe("odo push command tests", func() {
dir := envs["ODO_S2I_DEPLOYMENT_DIR"]

stdOut := oc.ExecListDir(podName, project, dir)
Expect(stdOut).To(ContainSubstring(("foobar.txt")))
Expect(stdOut).To(ContainSubstring(("testdir")))
helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})

// Now we delete the file and dir and push
helper.DeleteDir(newFilePath)
Expand All @@ -160,8 +159,7 @@ var _ = Describe("odo push command tests", func() {

// Then check to see if it's truly been deleted
stdOut = oc.ExecListDir(podName, project, dir)
Expect(stdOut).To(Not(ContainSubstring(("foobar.txt"))))
Expect(stdOut).To(Not(ContainSubstring(("testdir"))))
helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})
})

It("should build when a new file and a new folder is added in the directory", func() {
Expand Down
27 changes: 6 additions & 21 deletions tests/integration/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ func componentTests(args ...string) {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--min-memory", "100Mi", "--max-memory", "300Mi", "--min-cpu", "0.1", "--max-cpu", "2", "--context", context, "--app", "testing")...)
helper.ValidateLocalCmpExist(context, "Type,nodejs", "Name,cmp-git", "Application,testing", "MinCPU,100m")
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", context)...)
Expect(cmpList).To(ContainSubstring("cmp-git"))
Expect(cmpList).To(ContainSubstring("Not Pushed"))
helper.MatchAllInOutput(cmpList, []string{"cmp-git", "Not Pushed"})
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context)...)
})
It("should list the state as unknown for disconnected cluster", func() {
Expand All @@ -220,8 +219,7 @@ func componentTests(args ...string) {
kubeconfigOrig := os.Getenv("KUBECONFIG")
os.Setenv("KUBECONFIG", "/no/such/path")
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", context, "--v", "9")...)
Expect(cmpList).To(ContainSubstring("cmp-git"))
Expect(cmpList).To(ContainSubstring("Unknown"))
helper.MatchAllInOutput(cmpList, []string{"cmp-git", "Unknown"})
// KUBECONFIG defaults to ~/.kube/config so it can be empty in some cases.
if kubeconfigOrig != "" {
os.Setenv("KUBECONFIG", kubeconfigOrig)
Expand All @@ -239,13 +237,7 @@ func componentTests(args ...string) {
helper.CmdShouldPass("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", context)
helper.ValidateLocalCmpExist(context, "Type,nodejs", "Name,cmp-git", "Application,testing", "URL,0,Name,url-1")
cmpDescribe := helper.CmdShouldPass("odo", append(args, "describe", "--context", context)...)

Expect(cmpDescribe).To(ContainSubstring("cmp-git"))
Expect(cmpDescribe).To(ContainSubstring("nodejs"))
Expect(cmpDescribe).To(ContainSubstring("url-1"))
Expect(cmpDescribe).To(ContainSubstring("url-2"))
Expect(cmpDescribe).To(ContainSubstring("https://github.com/openshift/nodejs-ex"))
Expect(cmpDescribe).To(ContainSubstring("storage-1"))
helper.MatchAllInOutput(cmpDescribe, []string{"cmp-git", "nodejs", "url-1", "url-2", "https://github.com/openshift/nodejs-ex", "storage-1"})

cmpDescribeJSON, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "describe", "-o", "json", "--context", context)...))
Expect(err).Should(BeNil())
Expand Down Expand Up @@ -290,11 +282,7 @@ func componentTests(args ...string) {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git-2", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--context", context2, "--app", "testing")...)
helper.ValidateLocalCmpExist(context2, "Type,nodejs", "Name,cmp-git-2", "Application,testing")
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", context2)...)

Expect(cmpList).To(ContainSubstring("cmp-git"))
Expect(cmpList).To(ContainSubstring("cmp-git-2"))
Expect(cmpList).To(ContainSubstring("Not Pushed"))
Expect(cmpList).To(ContainSubstring("Pushed"))
helper.MatchAllInOutput(cmpList, []string{"cmp-git", "cmp-git-2", "Not Pushed", "Pushed"})

helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context)...)
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context2)...)
Expand All @@ -305,8 +293,7 @@ func componentTests(args ...string) {

// Since components catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time.
output := helper.CmdShouldPass("odo", "catalog", "list", "components", "-o", "json")
Expect(output).To(ContainSubstring("List"))
Expect(output).To(ContainSubstring("supportedTags"))
helper.MatchAllInOutput(output, []string{"List", "supportedTags"})
})

It("binary component should not fail when --context is not set", func() {
Expand Down Expand Up @@ -668,9 +655,7 @@ func componentTests(args ...string) {
cmpListOutput := helper.CmdShouldPass("odo", append(args, "list")...)
Expect(cmpListOutput).To(ContainSubstring(cmpName))
cmpDescribe := helper.CmdShouldPass("odo", append(args, "describe")...)

Expect(cmpDescribe).To(ContainSubstring(cmpName))
Expect(cmpDescribe).To(ContainSubstring("nodejs"))
helper.MatchAllInOutput(cmpDescribe, []string{cmpName, "nodejs"})

url := helper.DetermineRouteURL(context)
Expect(cmpDescribe).To(ContainSubstring(url))
Expand Down
27 changes: 8 additions & 19 deletions tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ var _ = Describe("odo devfile push command tests", func() {
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)

stdOut := oc.ExecListDir(podName, namespace, sourcePath)
Expect(stdOut).To(ContainSubstring(("foobar.txt")))
Expect(stdOut).To(ContainSubstring(("testdir")))
helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})

// Now we delete the file and dir and push
helper.DeleteDir(newFilePath)
Expand All @@ -116,8 +115,7 @@ var _ = Describe("odo devfile push command tests", func() {

// Then check to see if it's truly been deleted
stdOut = oc.ExecListDir(podName, namespace, sourcePath)
Expect(stdOut).To(Not(ContainSubstring(("foobar.txt"))))
Expect(stdOut).To(Not(ContainSubstring(("testdir"))))
helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})
})

It("should delete the files from the container if its removed locally", func() {
Expand Down Expand Up @@ -194,9 +192,7 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile-init.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(output).To(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devbuild command \"/artifacts/bin/build-container-full.sh\""))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devinit command \"echo hello", "Executing devbuild command \"/artifacts/bin/build-container-full.sh\"", "Executing devrun command \"/artifacts/bin/start-server.sh\""})
})

It("should execute devinit and devrun commands if present", func() {
Expand All @@ -206,8 +202,7 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile-init-without-build.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(output).To(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devinit command \"echo hello", "Executing devrun command \"/artifacts/bin/start-server.sh\""})
})

It("should only execute devinit command once if component is already created", func() {
Expand All @@ -217,15 +212,12 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile-init.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(output).To(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devbuild command \"/artifacts/bin/build-container-full.sh\""))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devinit command \"echo hello", "Executing devbuild command \"/artifacts/bin/build-container-full.sh\"", "Executing devrun command \"/artifacts/bin/start-server.sh\""})

// Need to force so build and run get triggered again with the component already created.
output = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace, "-f")
Expect(output).NotTo(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devbuild command \"/artifacts/bin/build-container-full.sh\""))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devbuild command \"/artifacts/bin/build-container-full.sh\"", "Executing devrun command \"/artifacts/bin/start-server.sh\""})
})

It("should be able to handle a missing devinit command", func() {
Expand All @@ -236,8 +228,7 @@ var _ = Describe("odo devfile push command tests", func() {

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(output).NotTo(ContainSubstring("Executing devinit command"))
Expect(output).To(ContainSubstring("Executing devbuild command \"npm install\""))
Expect(output).To(ContainSubstring("Executing devrun command \"nodemon app.js\""))
helper.MatchAllInOutput(output, []string{"Executing devbuild command \"npm install\"", "Executing devrun command \"nodemon app.js\""})
})

It("should be able to handle a missing devbuild command", func() {
Expand Down Expand Up @@ -267,9 +258,7 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-volumes.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(output).To(ContainSubstring("Executing devinit command"))
Expect(output).To(ContainSubstring("Executing devbuild command"))
Expect(output).To(ContainSubstring("Executing devrun command"))
helper.MatchAllInOutput(output, []string{"Executing devinit command", "Executing devbuild command", "Executing devrun command"})

// Check to see if it's been pushed (foobar.txt abd directory testdir)
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)
Expand Down
12 changes: 4 additions & 8 deletions tests/integration/devfile/cmd_devfile_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ var _ = Describe("odo devfile url command tests", func() {

helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
pushStdOut := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(pushStdOut).NotTo(ContainSubstring("successfully deleted"))
Expect(pushStdOut).NotTo(ContainSubstring("created"))
helper.DontMatchAllInOutput(pushStdOut, []string{"successfully deleted", "created"})
Expect(pushStdOut).To(ContainSubstring("URLs are synced with the cluster, no changes are required"))

output := helper.CmdShouldPass("oc", "get", "routes", "--namespace", namespace)
Expand All @@ -167,8 +166,7 @@ var _ = Describe("odo devfile url command tests", func() {
helper.CmdShouldPass("odo", "url", "delete", url1, "-f")
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
pushStdOut = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expect(pushStdOut).NotTo(ContainSubstring("successfully deleted"))
Expect(pushStdOut).NotTo(ContainSubstring("created"))
helper.DontMatchAllInOutput(pushStdOut, []string{"successfully deleted", "created"})
Expect(pushStdOut).To(ContainSubstring("URLs are synced with the cluster, no changes are required"))

output = helper.CmdShouldPass("oc", "get", "routes", "--namespace", namespace)
Expand Down Expand Up @@ -205,16 +203,14 @@ var _ = Describe("odo devfile url command tests", func() {

helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)
stdOut = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)
Expect(stdOut).NotTo(ContainSubstring("successfully deleted"))
Expect(stdOut).NotTo(ContainSubstring("created"))
helper.DontMatchAllInOutput(stdOut, []string{"successfully deleted", "created"})
Expect(stdOut).To(ContainSubstring("URLs are synced with the cluster, no changes are required"))

helper.CmdShouldPass("odo", "url", "delete", url1, "-f")

helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)
stdOut = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)
Expect(stdOut).NotTo(ContainSubstring("successfully deleted"))
Expect(stdOut).NotTo(ContainSubstring("created"))
helper.DontMatchAllInOutput(stdOut, []string{"successfully deleted", "created"})
Expect(stdOut).To(ContainSubstring("URLs are synced with the cluster, no changes are required"))
})
})
Expand Down
13 changes: 4 additions & 9 deletions tests/integration/devfile/docker/cmd_docker_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ var _ = Describe("odo docker devfile push command tests", func() {
Expect(len(containers)).To(Equal(1))

stdOut := dockerClient.ExecContainer(containers[0], "ls -la "+sourcePath)
Expect(stdOut).To(ContainSubstring(("foobar.txt")))
Expect(stdOut).To(ContainSubstring(("testdir")))
helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})

// Now we delete the file and dir and push
helper.DeleteDir(newFilePath)
Expand All @@ -130,8 +129,7 @@ var _ = Describe("odo docker devfile push command tests", func() {

// Then check to see if it's truly been deleted
stdOut = dockerClient.ExecContainer(containers[0], "ls -la "+sourcePath)
Expect(stdOut).To(Not(ContainSubstring(("foobar.txt"))))
Expect(stdOut).To(Not(ContainSubstring(("testdir"))))
helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})
})

It("should build when no changes are detected in the directory and force flag is enabled", func() {
Expand All @@ -156,9 +154,7 @@ var _ = Describe("odo docker devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile-init.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml")
Expect(output).To(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devbuild command \"/artifacts/bin/build-container-full.sh\""))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devinit command \"echo hello", "Executing devbuild command \"/artifacts/bin/build-container-full.sh\"", "Executing devrun command \"/artifacts/bin/start-server.sh\""})

// Check to see if it's been pushed (foobar.txt abd directory testdir)
containers := dockerClient.GetRunningContainersByCompAlias(cmpName, "runtime")
Expand All @@ -175,8 +171,7 @@ var _ = Describe("odo docker devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "springboot", "devfile-init-without-build.yaml"), filepath.Join(context, "devfile.yaml"))

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml")
Expect(output).To(ContainSubstring("Executing devinit command \"echo hello"))
Expect(output).To(ContainSubstring("Executing devrun command \"/artifacts/bin/start-server.sh\""))
helper.MatchAllInOutput(output, []string{"Executing devinit command \"echo hello", "Executing devrun command \"/artifacts/bin/start-server.sh\""})

// Check to see if it's been pushed (foobar.txt abd directory testdir)
containers := dockerClient.GetRunningContainersByCompAlias(cmpName, "runtime")
Expand Down
Loading

0 comments on commit 7cb1695

Please sign in to comment.