Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace multiple expect statement with MatchAllInOutput and DontMatchAllInOutput #3251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tests/e2escenarios/e2e_beta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ 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{"UpdateNotification", "NamePrefix", "Timeout", "PushTarget"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format this line as its more then 120 characters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format this line as its more then 120 characters

Its hard time for me to understand what you are pointing to. Can you please give a example or a reference would really be helpful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this command into multiple lines as a single line of code shouldn’t be more then 120 characters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am talking about the line mentioned in the comment below this git comment

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
34 changes: 13 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,14 @@ 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 +289,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 +300,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 +662,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
48 changes: 29 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,11 @@ 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 +206,10 @@ 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 +219,19 @@ 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 +242,10 @@ 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 +275,11 @@ 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
Loading