From f280a61b0d5690976a77266aeda79b6efd5c04a2 Mon Sep 17 00:00:00 2001 From: Rodolfo Napoles Date: Thu, 28 Apr 2022 15:50:04 -0400 Subject: [PATCH] refactoring generic-test (#5628) * rebasing * Incorporated additional feedback, removed make test-generic from openshift-tests.sh as it runs test-integration --- .ibm/pipelines/kubernetes-tests.sh | 2 + .ibm/pipelines/openshift-tests.sh | 1 + tests/integration/generic_test.go | 69 ++++++++++++++++-------------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/.ibm/pipelines/kubernetes-tests.sh b/.ibm/pipelines/kubernetes-tests.sh index 9944ccd8e..02ac58c8e 100755 --- a/.ibm/pipelines/kubernetes-tests.sh +++ b/.ibm/pipelines/kubernetes-tests.sh @@ -17,7 +17,9 @@ cleanup_namespaces make test-interactive make test-e2e-devfile make test-cmd-project + make test-generic ) |& tee "/tmp/${LOGFILE}" + RESULT=${PIPESTATUS[0]} save_logs "${LOGFILE}" "Kubernetes Tests" ${RESULT} diff --git a/.ibm/pipelines/openshift-tests.sh b/.ibm/pipelines/openshift-tests.sh index aface5b50..76afc0fc3 100755 --- a/.ibm/pipelines/openshift-tests.sh +++ b/.ibm/pipelines/openshift-tests.sh @@ -21,6 +21,7 @@ cleanup_namespaces make test-cmd-project make test-e2e-devfile ) |& tee "/tmp/${LOGFILE}" + RESULT=${PIPESTATUS[0]} save_logs "${LOGFILE}" "OpenShift Tests" ${RESULT} diff --git a/tests/integration/generic_test.go b/tests/integration/generic_test.go index ef94d9c7a..96a9e8d3c 100644 --- a/tests/integration/generic_test.go +++ b/tests/integration/generic_test.go @@ -2,7 +2,6 @@ package integration import ( "regexp" - "strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -27,28 +26,30 @@ var _ = Describe("odo generic", func() { helper.CommonAfterEach(commonVar) }) - Context("Check the help usage for odo", func() { + When("running odo --help", func() { + var output string + BeforeEach(func() { + output = helper.Cmd("odo", "--help").ShouldPass().Out() + }) + It("retuns full help contents including usage, examples, commands, utility commands, component shortcuts, and flags sections", func() { + helper.MatchAllInOutput(output, []string{"Usage:", "Examples:", "Main Commands:", "OpenShift Commands:", "Utility Commands:", "Flags:"}) + }) - It("Makes sure that we have the long-description when running odo and we dont error", func() { - output := helper.Cmd("odo").ShouldPass().Out() + }) + + When("running odo without subcommand and flags", func() { + var output string + BeforeEach(func() { + output = helper.Cmd("odo").ShouldPass().Out() + }) + It("a short vesion of help contents is returned, an error is not expected", func() { Expect(output).To(ContainSubstring("To see a full list of commands, run 'odo --help'")) }) + }) - It("Make sure we have the full description when performing odo --help", func() { - output := helper.Cmd("odo", "--help").ShouldPass().Out() - Expect(output).To(ContainSubstring("Use \"odo [command] --help\" for more information about a command.")) - }) - - It("Fail when entering an incorrect name for a component", func() { - output := helper.Cmd("odo", "delete", "foobar").ShouldFail().Err() - Expect(output).To(ContainSubstring("Subcommand not found, use one of the available commands")) - }) - - It("Fail with showing help only once for incorrect command", func() { - output := helper.Cmd("odo", "hello").ShouldFail().Err() - Expect(strings.Count(output, "odo [flags]")).Should(Equal(1)) - }) - + It("returns error when using an invalid command", func() { + output := helper.Cmd("odo", "hello").ShouldFail().Err() + Expect(output).To(ContainSubstring("Invalid command - see available commands/subcommands above")) }) Context("When deleting two project one after the other", func() { @@ -56,35 +57,37 @@ var _ = Describe("odo generic", func() { project1 := helper.CreateRandProject() project2 := helper.CreateRandProject() - helper.DeleteProject(project2) helper.DeleteProject(project1) + helper.DeleteProject(project2) }) - }) - - Context("When deleting three project one after the other in opposite order", func() { - It("should be able to delete", func() { + It("should be able to delete them in any order", func() { project1 := helper.CreateRandProject() project2 := helper.CreateRandProject() project3 := helper.CreateRandProject() - helper.DeleteProject(project1) helper.DeleteProject(project2) + helper.DeleteProject(project1) helper.DeleteProject(project3) - }) }) - Context("when executing odo version command", func() { + When("executing odo version command", func() { + var odoVersion string + BeforeEach(func() { + odoVersion = helper.Cmd("odo", "version").ShouldPass().Out() + }) + It("should show the version of odo major components including server login URL", func() { - odoVersion := helper.Cmd("odo", "version").ShouldPass().Out() reOdoVersion := regexp.MustCompile(`^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`) odoVersionStringMatch := reOdoVersion.MatchString(odoVersion) - rekubernetesVersion := regexp.MustCompile(`Kubernetes:\s*v[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`) - kubernetesVersionStringMatch := rekubernetesVersion.MatchString(odoVersion) Expect(odoVersionStringMatch).Should(BeTrue()) - Expect(kubernetesVersionStringMatch).Should(BeTrue()) - serverURL := oc.GetCurrentServerURL() - Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL)) + if !helper.IsKubernetesCluster() { + rekubernetesVersion := regexp.MustCompile(`Kubernetes:\s*v[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`) + kubernetesVersionStringMatch := rekubernetesVersion.MatchString(odoVersion) + Expect(kubernetesVersionStringMatch).Should(BeTrue()) + serverURL := oc.GetCurrentServerURL() + Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL)) + } }) })