From 1701d237f7f843a22f956173691bcd5704d8f877 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Wed, 29 Apr 2020 14:11:02 +0530 Subject: [PATCH 1/9] Running devfile push integration test on kubernetes cluster --- .travis.yml | 3 +- scripts/oc-cluster.sh | 4 +- .../devfile/cmd_devfile_push_test.go | 64 +++++++++++-------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f8f932799e..14586a1d185 100644 --- a/.travis.yml +++ b/.travis.yml @@ -175,7 +175,7 @@ jobs: # Run devfile integration test on Kubernetes cluster - <<: *base-test stage: test - name: "devfile catalog and watch command integration tests on kubernetes cluster" + name: "devfile catalog, watch, push command integration tests on kubernetes cluster" before_script: # Download kubectl, a cli tool for accessing Kubernetes cluster - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ @@ -192,3 +192,4 @@ jobs: - export KUBERNETES=true - travis_wait make test-cmd-devfile-catalog - travis_wait make test-cmd-devfile-watch + - travis_wait make test-cmd-devfile-push \ No newline at end of file diff --git a/scripts/oc-cluster.sh b/scripts/oc-cluster.sh index 88b8a24aca9..58200d94479 100755 --- a/scripts/oc-cluster.sh +++ b/scripts/oc-cluster.sh @@ -28,12 +28,12 @@ sudo docker run -v /:/rootfs -ti --rm --entrypoint=/bin/bash --privileged opensh while true; do if [ "$1" = "service-catalog" ]; then - oc cluster up --base-dir=$HOME/oscluster + oc cluster up --base-dir=$HOME/oscluster --skip-registry-check=true oc cluster add --base-dir=$HOME/oscluster service-catalog oc cluster add --base-dir=$HOME/oscluster template-service-broker oc cluster add --base-dir=$HOME/oscluster automation-service-broker else - oc cluster up + oc cluster up --skip-registry-check=true fi if [ "$?" -eq 0 ]; then ./scripts/travis-check-pods.sh $1 diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index 508cdcf96b5..d428b3c2f09 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -16,31 +16,45 @@ import ( var _ = Describe("odo devfile push command tests", func() { var namespace, context, cmpName, currentWorkingDirectory string var sourcePath = "/projects/nodejs-web-app" + var clusterType helper.CliRunner - // TODO: all oc commands in all devfile related test should get replaced by kubectl - // TODO: to goal is not to use "oc" - oc := helper.NewOcRunner("oc") + // Using program commmand according to cluter type in devfile + if os.Getenv("KUBERNETES") == "true" { + clusterType = helper.NewKubectlRunner("kubectl") + } else { + clusterType = helper.NewOcRunner("oc") + } // This is run after every Spec (It) var _ = BeforeEach(func() { SetDefaultEventuallyTimeout(10 * time.Minute) - namespace = helper.CreateRandProject() context = helper.CreateNewContext() - currentWorkingDirectory = helper.Getwd() - cmpName = helper.RandString(6) - - helper.Chdir(context) - os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") + + if os.Getenv("KUBERNETES") == "true" { + homeDir := helper.GetUserHomeDir() + kubeConfigFile := helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + namespace = helper.CreateRandNamespace(kubeConfigFile) + } else { + namespace = helper.CreateRandProject() + } + currentWorkingDirectory = helper.Getwd() + cmpName = helper.RandString(6) + helper.Chdir(context) }) // Clean up after the test // This is run after every Spec (It) var _ = AfterEach(func() { - helper.DeleteProject(namespace) + if os.Getenv("KUBERNETES") == "true" { + helper.DeleteNamespace(namespace) + os.Unsetenv("KUBECONFIG") + } else { + helper.DeleteProject(namespace) + } helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") @@ -56,14 +70,14 @@ var _ = Describe("odo devfile push command tests", func() { helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-no-endpoints.yaml"), filepath.Join(context, "devfile.yaml")) helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) - output := oc.GetServices(namespace) + output := clusterType.GetServices(namespace) Expect(output).NotTo(ContainSubstring(cmpName)) helper.RenameFile("devfile-old.yaml", "devfile.yaml") output = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) Expect(output).To(ContainSubstring("Changes successfully pushed to component")) - output = oc.GetServices(namespace) + output = clusterType.GetServices(namespace) Expect(output).To(ContainSubstring(cmpName)) }) @@ -103,9 +117,9 @@ var _ = Describe("odo devfile push command tests", func() { utils.ExecPushWithNewFileAndDir(context, cmpName, namespace, newFilePath, newDirPath) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := oc.GetRunningPodNameByComponent(cmpName, namespace) + podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) - stdOut := oc.ExecListDir(podName, namespace, sourcePath) + stdOut := clusterType.ExecListDir(podName, namespace, sourcePath) helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"}) // Now we delete the file and dir and push @@ -114,7 +128,7 @@ var _ = Describe("odo devfile push command tests", func() { helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace, "-v4") // Then check to see if it's truly been deleted - stdOut = oc.ExecListDir(podName, namespace, sourcePath) + stdOut = clusterType.ExecListDir(podName, namespace, sourcePath) helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"}) }) @@ -127,10 +141,10 @@ var _ = Describe("odo devfile push command tests", func() { helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := oc.GetRunningPodNameByComponent(cmpName, namespace) + podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) var statErr error - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "", namespace, @@ -144,7 +158,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(os.Remove(filepath.Join(context, "app", "app.js"))).NotTo(HaveOccurred()) helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "", namespace, @@ -166,11 +180,11 @@ var _ = Describe("odo devfile push command tests", func() { utils.ExecDefaultDevfileCommands(context, cmpName, namespace) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := oc.GetRunningPodNameByComponent(cmpName, namespace) + podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) var statErr error var cmdOutput string - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "runtime", namespace, @@ -282,11 +296,11 @@ var _ = Describe("odo devfile push command tests", func() { }) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := oc.GetRunningPodNameByComponent(cmpName, namespace) + podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) var statErr error var cmdOutput string - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "runtime", namespace, @@ -300,7 +314,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(statErr).ToNot(HaveOccurred()) Expect(cmdOutput).To(ContainSubstring("init")) - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "runtime2", namespace, @@ -314,7 +328,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(statErr).ToNot(HaveOccurred()) Expect(cmdOutput).To(ContainSubstring("hello")) - oc.CheckCmdOpInRemoteDevfilePod( + clusterType.CheckCmdOpInRemoteDevfilePod( podName, "runtime2", namespace, @@ -329,7 +343,7 @@ var _ = Describe("odo devfile push command tests", func() { volumesMatched := false // check the volume name and mount paths for the containers - volNamesAndPaths := oc.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace) + volNamesAndPaths := clusterType.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace) volNamesAndPathsArr := strings.Fields(volNamesAndPaths) for _, volNamesAndPath := range volNamesAndPathsArr { volNamesAndPathArr := strings.Split(volNamesAndPath, ":") From ad1bd50108d65641dd070efb7a95352ba3c9439f Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Tue, 5 May 2020 16:25:39 +0530 Subject: [PATCH 2/9] Updated xenial insecure registry path --- .travis.yml | 2 +- scripts/oc-cluster.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14586a1d185..9f661fa212c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -175,7 +175,7 @@ jobs: # Run devfile integration test on Kubernetes cluster - <<: *base-test stage: test - name: "devfile catalog, watch, push command integration tests on kubernetes cluster" + name: "devfile catalog, watch and push command integration tests on kubernetes cluster" before_script: # Download kubectl, a cli tool for accessing Kubernetes cluster - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ diff --git a/scripts/oc-cluster.sh b/scripts/oc-cluster.sh index 58200d94479..88b8a24aca9 100755 --- a/scripts/oc-cluster.sh +++ b/scripts/oc-cluster.sh @@ -28,12 +28,12 @@ sudo docker run -v /:/rootfs -ti --rm --entrypoint=/bin/bash --privileged opensh while true; do if [ "$1" = "service-catalog" ]; then - oc cluster up --base-dir=$HOME/oscluster --skip-registry-check=true + oc cluster up --base-dir=$HOME/oscluster oc cluster add --base-dir=$HOME/oscluster service-catalog oc cluster add --base-dir=$HOME/oscluster template-service-broker oc cluster add --base-dir=$HOME/oscluster automation-service-broker else - oc cluster up --skip-registry-check=true + oc cluster up fi if [ "$?" -eq 0 ]; then ./scripts/travis-check-pods.sh $1 From 17cfa24c280222c89ce00fbeb3e45294fe34b3fb Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Mon, 11 May 2020 11:22:40 +0530 Subject: [PATCH 3/9] Modifying Runner variable name to cliRunner --- .travis.yml | 130 +++++++++--------- tests/helper/kubernetes_utils.go | 4 +- .../devfile/cmd_devfile_catalog_test.go | 4 +- .../devfile/cmd_devfile_push_test.go | 42 +++--- .../devfile/cmd_devfile_registry_test.go | 2 +- .../devfile/cmd_devfile_watch_test.go | 4 +- 6 files changed, 93 insertions(+), 93 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f661fa212c..5b6db66193d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,61 +68,61 @@ jobs: - make test after_success: skip - - <<: *base-test - stage: test - name: "generic, login and component command integration tests" - script: - - ./scripts/oc-cluster.sh - - make bin - - sudo cp odo /usr/bin - - odo login -u developer - - travis_wait make test-generic - - travis_wait make test-cmd-login-logout - - travis_wait make test-cmd-cmp - - odo logout + # - <<: *base-test + # stage: test + # name: "generic, login and component command integration tests" + # script: + # - ./scripts/oc-cluster.sh + # - make bin + # - sudo cp odo /usr/bin + # - odo login -u developer + # - travis_wait make test-generic + # - travis_wait make test-cmd-login-logout + # - travis_wait make test-cmd-cmp + # - odo logout - - <<: *base-test - stage: test - name: "preference, config, url and debug command integration tests" - script: - - ./scripts/oc-cluster.sh - - make bin - - sudo cp odo /usr/bin - - odo login -u developer - - travis_wait make test-cmd-pref-config - - travis_wait make test-cmd-url - - travis_wait make test-cmd-devfile-url - - travis_wait make test-cmd-debug - - odo logout + # - <<: *base-test + # stage: test + # name: "preference, config, url and debug command integration tests" + # script: + # - ./scripts/oc-cluster.sh + # - make bin + # - sudo cp odo /usr/bin + # - odo login -u developer + # - travis_wait make test-cmd-pref-config + # - travis_wait make test-cmd-url + # - travis_wait make test-cmd-devfile-url + # - travis_wait make test-cmd-debug + # - odo logout - # Run service-catalog e2e tests - - <<: *base-test - stage: test - name: "service, link and component sub-commands command integration tests" - script: - - ./scripts/oc-cluster.sh service-catalog - - make bin - - sudo cp odo /usr/bin - - odo login -u developer - - travis_wait make test-cmd-service - - travis_wait make test-cmd-link-unlink - - travis_wait make test-cmd-cmp-sub - - odo logout + # # Run service-catalog e2e tests + # - <<: *base-test + # stage: test + # name: "service, link and component sub-commands command integration tests" + # script: + # - ./scripts/oc-cluster.sh service-catalog + # - make bin + # - sudo cp odo /usr/bin + # - odo login -u developer + # - travis_wait make test-cmd-service + # - travis_wait make test-cmd-link-unlink + # - travis_wait make test-cmd-cmp-sub + # - odo logout - - <<: *base-test - stage: test - name: "watch, storage, app, project and push command integration tests" - script: - - ./scripts/oc-cluster.sh - - make bin - - sudo cp odo /usr/bin - - odo login -u developer - - travis_wait make test-cmd-watch - - travis_wait make test-cmd-storage - - travis_wait make test-cmd-app - - travis_wait make test-cmd-push - - travis_wait make test-cmd-project - - odo logout + # - <<: *base-test + # stage: test + # name: "watch, storage, app, project and push command integration tests" + # script: + # - ./scripts/oc-cluster.sh + # - make bin + # - sudo cp odo /usr/bin + # - odo login -u developer + # - travis_wait make test-cmd-watch + # - travis_wait make test-cmd-storage + # - travis_wait make test-cmd-app + # - travis_wait make test-cmd-push + # - travis_wait make test-cmd-project + # - odo logout - <<: *base-test stage: test @@ -146,19 +146,19 @@ jobs: - travis_wait make test-cmd-devfile-registry - odo logout - - <<: *base-test - stage: test - name: "core beta, java, source e2e tests" - script: - - ./scripts/oc-cluster.sh - - make bin - - sudo cp odo /usr/bin - - odo login -u developer - - travis_wait make test-e2e-beta - - travis_wait make test-e2e-java - - travis_wait make test-e2e-source - - travis_wait make test-e2e-images - - odo logout + # - <<: *base-test + # stage: test + # name: "core beta, java, source e2e tests" + # script: + # - ./scripts/oc-cluster.sh + # - make bin + # - sudo cp odo /usr/bin + # - odo login -u developer + # - travis_wait make test-e2e-beta + # - travis_wait make test-e2e-java + # - travis_wait make test-e2e-source + # - travis_wait make test-e2e-images + # - odo logout - <<: *base-test stage: test diff --git a/tests/helper/kubernetes_utils.go b/tests/helper/kubernetes_utils.go index 5900ec4f150..2a3142dc56b 100644 --- a/tests/helper/kubernetes_utils.go +++ b/tests/helper/kubernetes_utils.go @@ -19,11 +19,11 @@ func CopyKubeConfigFile(kubeConfigFile, tempConfigFile string) string { } // CreateRandNamespace create new project with random name in kubernetes cluster (10 letters) -func CreateRandNamespace(context string) string { +func CreateRandNamespace() string { projectName := RandString(10) fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName) CmdShouldPass("kubectl", "create", "namespace", projectName) - CmdShouldPass("kubectl", "config", "set-context", context, "--namespace", projectName) + CmdShouldPass("kubectl", "config", "set-context", "--current", "--namespace", projectName) session := CmdShouldPass("kubectl", "get", "namespaces") Expect(session).To(ContainSubstring(projectName)) return projectName diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index afb36767742..e5a4819cc30 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -23,8 +23,8 @@ var _ = Describe("odo devfile catalog command tests", func() { helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") if os.Getenv("KUBERNETES") == "true" { homeDir := helper.GetUserHomeDir() - kubeConfigFile := helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - project = helper.CreateRandNamespace(kubeConfigFile) + _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + project = helper.CreateRandNamespace() } else { project = helper.CreateRandProject() } diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index d428b3c2f09..faaa413c550 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -16,13 +16,13 @@ import ( var _ = Describe("odo devfile push command tests", func() { var namespace, context, cmpName, currentWorkingDirectory string var sourcePath = "/projects/nodejs-web-app" - var clusterType helper.CliRunner + var cliRunner helper.CliRunner - // Using program commmand according to cluter type in devfile + // Using program commmand according to cliRunner in devfile if os.Getenv("KUBERNETES") == "true" { - clusterType = helper.NewKubectlRunner("kubectl") + cliRunner = helper.NewKubectlRunner("kubectl") } else { - clusterType = helper.NewOcRunner("oc") + cliRunner = helper.NewOcRunner("oc") } // This is run after every Spec (It) @@ -36,8 +36,8 @@ var _ = Describe("odo devfile push command tests", func() { if os.Getenv("KUBERNETES") == "true" { homeDir := helper.GetUserHomeDir() - kubeConfigFile := helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - namespace = helper.CreateRandNamespace(kubeConfigFile) + _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + namespace = helper.CreateRandNamespace() } else { namespace = helper.CreateRandProject() } @@ -70,14 +70,14 @@ var _ = Describe("odo devfile push command tests", func() { helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-no-endpoints.yaml"), filepath.Join(context, "devfile.yaml")) helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) - output := clusterType.GetServices(namespace) + output := cliRunner.GetServices(namespace) Expect(output).NotTo(ContainSubstring(cmpName)) helper.RenameFile("devfile-old.yaml", "devfile.yaml") output = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) Expect(output).To(ContainSubstring("Changes successfully pushed to component")) - output = clusterType.GetServices(namespace) + output = cliRunner.GetServices(namespace) Expect(output).To(ContainSubstring(cmpName)) }) @@ -117,9 +117,9 @@ var _ = Describe("odo devfile push command tests", func() { utils.ExecPushWithNewFileAndDir(context, cmpName, namespace, newFilePath, newDirPath) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) + podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace) - stdOut := clusterType.ExecListDir(podName, namespace, sourcePath) + stdOut := cliRunner.ExecListDir(podName, namespace, sourcePath) helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"}) // Now we delete the file and dir and push @@ -128,7 +128,7 @@ var _ = Describe("odo devfile push command tests", func() { helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace, "-v4") // Then check to see if it's truly been deleted - stdOut = clusterType.ExecListDir(podName, namespace, sourcePath) + stdOut = cliRunner.ExecListDir(podName, namespace, sourcePath) helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"}) }) @@ -141,10 +141,10 @@ var _ = Describe("odo devfile push command tests", func() { helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) + podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace) var statErr error - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "", namespace, @@ -158,7 +158,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(os.Remove(filepath.Join(context, "app", "app.js"))).NotTo(HaveOccurred()) helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "", namespace, @@ -180,11 +180,11 @@ var _ = Describe("odo devfile push command tests", func() { utils.ExecDefaultDevfileCommands(context, cmpName, namespace) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) + podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace) var statErr error var cmdOutput string - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "runtime", namespace, @@ -296,11 +296,11 @@ var _ = Describe("odo devfile push command tests", func() { }) // Check to see if it's been pushed (foobar.txt abd directory testdir) - podName := clusterType.GetRunningPodNameByComponent(cmpName, namespace) + podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace) var statErr error var cmdOutput string - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "runtime", namespace, @@ -314,7 +314,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(statErr).ToNot(HaveOccurred()) Expect(cmdOutput).To(ContainSubstring("init")) - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "runtime2", namespace, @@ -328,7 +328,7 @@ var _ = Describe("odo devfile push command tests", func() { Expect(statErr).ToNot(HaveOccurred()) Expect(cmdOutput).To(ContainSubstring("hello")) - clusterType.CheckCmdOpInRemoteDevfilePod( + cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "runtime2", namespace, @@ -343,7 +343,7 @@ var _ = Describe("odo devfile push command tests", func() { volumesMatched := false // check the volume name and mount paths for the containers - volNamesAndPaths := clusterType.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace) + volNamesAndPaths := cliRunner.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace) volNamesAndPathsArr := strings.Fields(volNamesAndPaths) for _, volNamesAndPath := range volNamesAndPathsArr { volNamesAndPathArr := strings.Split(volNamesAndPath, ":") diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index 85c27e0297c..b5ca3b3b88b 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -25,7 +25,7 @@ var _ = Describe("odo devfile registry command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") if os.Getenv("KUBERNETES") == "true" { - project = helper.CreateRandNamespace(context) + project = helper.CreateRandNamespace() } else { project = helper.CreateRandProject() } diff --git a/tests/integration/devfile/cmd_devfile_watch_test.go b/tests/integration/devfile/cmd_devfile_watch_test.go index c357812ad39..4b2c560f09b 100644 --- a/tests/integration/devfile/cmd_devfile_watch_test.go +++ b/tests/integration/devfile/cmd_devfile_watch_test.go @@ -29,8 +29,8 @@ var _ = Describe("odo devfile watch command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) if os.Getenv("KUBERNETES") == "true" { homeDir := helper.GetUserHomeDir() - kubeConfigFile := helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - namespace = helper.CreateRandNamespace(kubeConfigFile) + _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + namespace = helper.CreateRandNamespace() cliRunner = helper.NewKubectlRunner("kubectl") } else { namespace = helper.CreateRandProject() From 41a120e18854c9311aa5caf37e558ce210b93985 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Thu, 14 May 2020 11:21:11 +0530 Subject: [PATCH 4/9] Common project Create and Delete function according to the running cluster --- .travis.yml | 130 +++++++++--------- tests/helper/helper_cli.go | 2 + tests/helper/helper_kubectl.go | 17 +++ tests/helper/helper_oc.go | 17 +++ tests/helper/kubernetes_utils.go | 24 +--- .../devfile/cmd_devfile_catalog_test.go | 26 ++-- .../devfile/cmd_devfile_push_test.go | 18 +-- .../devfile/cmd_devfile_registry_test.go | 23 ++-- .../devfile/cmd_devfile_watch_test.go | 13 +- 9 files changed, 138 insertions(+), 132 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b6db66193d..9f661fa212c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,61 +68,61 @@ jobs: - make test after_success: skip - # - <<: *base-test - # stage: test - # name: "generic, login and component command integration tests" - # script: - # - ./scripts/oc-cluster.sh - # - make bin - # - sudo cp odo /usr/bin - # - odo login -u developer - # - travis_wait make test-generic - # - travis_wait make test-cmd-login-logout - # - travis_wait make test-cmd-cmp - # - odo logout + - <<: *base-test + stage: test + name: "generic, login and component command integration tests" + script: + - ./scripts/oc-cluster.sh + - make bin + - sudo cp odo /usr/bin + - odo login -u developer + - travis_wait make test-generic + - travis_wait make test-cmd-login-logout + - travis_wait make test-cmd-cmp + - odo logout - # - <<: *base-test - # stage: test - # name: "preference, config, url and debug command integration tests" - # script: - # - ./scripts/oc-cluster.sh - # - make bin - # - sudo cp odo /usr/bin - # - odo login -u developer - # - travis_wait make test-cmd-pref-config - # - travis_wait make test-cmd-url - # - travis_wait make test-cmd-devfile-url - # - travis_wait make test-cmd-debug - # - odo logout + - <<: *base-test + stage: test + name: "preference, config, url and debug command integration tests" + script: + - ./scripts/oc-cluster.sh + - make bin + - sudo cp odo /usr/bin + - odo login -u developer + - travis_wait make test-cmd-pref-config + - travis_wait make test-cmd-url + - travis_wait make test-cmd-devfile-url + - travis_wait make test-cmd-debug + - odo logout - # # Run service-catalog e2e tests - # - <<: *base-test - # stage: test - # name: "service, link and component sub-commands command integration tests" - # script: - # - ./scripts/oc-cluster.sh service-catalog - # - make bin - # - sudo cp odo /usr/bin - # - odo login -u developer - # - travis_wait make test-cmd-service - # - travis_wait make test-cmd-link-unlink - # - travis_wait make test-cmd-cmp-sub - # - odo logout + # Run service-catalog e2e tests + - <<: *base-test + stage: test + name: "service, link and component sub-commands command integration tests" + script: + - ./scripts/oc-cluster.sh service-catalog + - make bin + - sudo cp odo /usr/bin + - odo login -u developer + - travis_wait make test-cmd-service + - travis_wait make test-cmd-link-unlink + - travis_wait make test-cmd-cmp-sub + - odo logout - # - <<: *base-test - # stage: test - # name: "watch, storage, app, project and push command integration tests" - # script: - # - ./scripts/oc-cluster.sh - # - make bin - # - sudo cp odo /usr/bin - # - odo login -u developer - # - travis_wait make test-cmd-watch - # - travis_wait make test-cmd-storage - # - travis_wait make test-cmd-app - # - travis_wait make test-cmd-push - # - travis_wait make test-cmd-project - # - odo logout + - <<: *base-test + stage: test + name: "watch, storage, app, project and push command integration tests" + script: + - ./scripts/oc-cluster.sh + - make bin + - sudo cp odo /usr/bin + - odo login -u developer + - travis_wait make test-cmd-watch + - travis_wait make test-cmd-storage + - travis_wait make test-cmd-app + - travis_wait make test-cmd-push + - travis_wait make test-cmd-project + - odo logout - <<: *base-test stage: test @@ -146,19 +146,19 @@ jobs: - travis_wait make test-cmd-devfile-registry - odo logout - # - <<: *base-test - # stage: test - # name: "core beta, java, source e2e tests" - # script: - # - ./scripts/oc-cluster.sh - # - make bin - # - sudo cp odo /usr/bin - # - odo login -u developer - # - travis_wait make test-e2e-beta - # - travis_wait make test-e2e-java - # - travis_wait make test-e2e-source - # - travis_wait make test-e2e-images - # - odo logout + - <<: *base-test + stage: test + name: "core beta, java, source e2e tests" + script: + - ./scripts/oc-cluster.sh + - make bin + - sudo cp odo /usr/bin + - odo login -u developer + - travis_wait make test-e2e-beta + - travis_wait make test-e2e-java + - travis_wait make test-e2e-source + - travis_wait make test-e2e-images + - odo logout - <<: *base-test stage: test diff --git a/tests/helper/helper_cli.go b/tests/helper/helper_cli.go index c88e9b3f9bb..bebc9e004b3 100644 --- a/tests/helper/helper_cli.go +++ b/tests/helper/helper_cli.go @@ -12,4 +12,6 @@ type CliRunner interface { GetVolumeMountNamesandPathsFromContainer(deployName string, containerName, namespace string) string WaitAndCheckForExistence(resourceType, namespace string, timeoutMinutes int) bool GetServices(namespace string) string + CreateRandNamespaceProject() string + DeleteNamespaceProject(projectName string) } diff --git a/tests/helper/helper_kubectl.go b/tests/helper/helper_kubectl.go index 782fabba4eb..dfc516aa994 100644 --- a/tests/helper/helper_kubectl.go +++ b/tests/helper/helper_kubectl.go @@ -104,3 +104,20 @@ func (kubectl KubectlRunner) GetServices(namespace string) string { output := string(session.Wait().Out.Contents()) return output } + +// CreateRandNamespaceProject create new project with random name in kubernetes cluster (10 letters) +func (kubectl KubectlRunner) CreateRandNamespaceProject() string { + projectName := RandString(10) + fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName) + CmdShouldPass("kubectl", "create", "namespace", projectName) + CmdShouldPass("kubectl", "config", "set-context", "--current", "--namespace", projectName) + session := CmdShouldPass("kubectl", "get", "namespaces") + Expect(session).To(ContainSubstring(projectName)) + return projectName +} + +// DeleteNamespaceProject deletes a specified project in kubernetes cluster +func (kubectl KubectlRunner) DeleteNamespaceProject(projectName string) { + fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName) + CmdShouldPass("kubectl", "delete", "namespaces", projectName) +} diff --git a/tests/helper/helper_oc.go b/tests/helper/helper_oc.go index 6db401ccfc2..04072a16588 100644 --- a/tests/helper/helper_oc.go +++ b/tests/helper/helper_oc.go @@ -505,3 +505,20 @@ func (oc OcRunner) VerifyResourceDeleted(resourceType, resourceName, namespace s output := string(session.Wait().Out.Contents()) Expect(output).NotTo(ContainSubstring(resourceName)) } + +// CreateRandNamespaceProject create new project with random name in oc cluster (10 letters) +func (oc OcRunner) CreateRandNamespaceProject() string { + projectName := RandString(10) + fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName) + session := CmdShouldPass("odo", "project", "create", projectName, "-w", "-v4") + Expect(session).To(ContainSubstring("New project created")) + Expect(session).To(ContainSubstring(projectName)) + return projectName +} + +// DeleteNamespaceProject deletes a specified project in oc cluster +func (oc OcRunner) DeleteNamespaceProject(projectName string) { + fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName) + session := CmdShouldPass("odo", "project", "delete", projectName, "-f") + Expect(session).To(ContainSubstring("Deleted project : " + projectName)) +} diff --git a/tests/helper/kubernetes_utils.go b/tests/helper/kubernetes_utils.go index 2a3142dc56b..14024c0b6b1 100644 --- a/tests/helper/kubernetes_utils.go +++ b/tests/helper/kubernetes_utils.go @@ -1,36 +1,16 @@ package helper import ( - "fmt" "os" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) -// CopyKubeConfigFile copies default kubeconfig file into current context config file -func CopyKubeConfigFile(kubeConfigFile, tempConfigFile string) string { +// CopyKubeConfigFile copies default kubeconfig file into current temporary context config file +func CopyKubeConfigFile(kubeConfigFile, tempConfigFile string) { info, err := os.Stat(kubeConfigFile) Expect(err).NotTo(HaveOccurred()) err = copyFile(kubeConfigFile, tempConfigFile, info) Expect(err).NotTo(HaveOccurred()) os.Setenv("KUBECONFIG", tempConfigFile) - return tempConfigFile -} - -// CreateRandNamespace create new project with random name in kubernetes cluster (10 letters) -func CreateRandNamespace() string { - projectName := RandString(10) - fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName) - CmdShouldPass("kubectl", "create", "namespace", projectName) - CmdShouldPass("kubectl", "config", "set-context", "--current", "--namespace", projectName) - session := CmdShouldPass("kubectl", "get", "namespaces") - Expect(session).To(ContainSubstring(projectName)) - return projectName -} - -// DeleteNamespace deletes a specified project in kubernetes cluster -func DeleteNamespace(projectName string) { - fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName) - CmdShouldPass("kubectl", "delete", "namespaces", projectName) } diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index e5a4819cc30..184e05fd34c 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -14,6 +14,14 @@ var _ = Describe("odo devfile catalog command tests", func() { var project string var context string var currentWorkingDirectory string + var cliRunner helper.CliRunner + + // Using program commmand according to cliRunner in devfile + if os.Getenv("KUBERNETES") == "true" { + cliRunner = helper.NewKubectlRunner("kubectl") + } else { + cliRunner = helper.NewOcRunner("oc") + } // This is run after every Spec (It) var _ = BeforeEach(func() { @@ -21,25 +29,17 @@ var _ = Describe("odo devfile catalog command tests", func() { context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - homeDir := helper.GetUserHomeDir() - _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - project = helper.CreateRandNamespace() - } else { - project = helper.CreateRandProject() - } + homeDir := helper.GetUserHomeDir() + helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) }) // This is run after every Spec (It) var _ = AfterEach(func() { - if os.Getenv("KUBERNETES") == "true" { - helper.DeleteNamespace(project) - os.Unsetenv("KUBECONFIG") - } else { - helper.DeleteProject(project) - } + cliRunner.DeleteNamespaceProject(project) + os.Unsetenv("KUBECONFIG") helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index faaa413c550..c408214ecbe 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -34,13 +34,9 @@ var _ = Describe("odo devfile push command tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - homeDir := helper.GetUserHomeDir() - _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - namespace = helper.CreateRandNamespace() - } else { - namespace = helper.CreateRandProject() - } + homeDir := helper.GetUserHomeDir() + helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() cmpName = helper.RandString(6) helper.Chdir(context) @@ -49,12 +45,8 @@ var _ = Describe("odo devfile push command tests", func() { // Clean up after the test // This is run after every Spec (It) var _ = AfterEach(func() { - if os.Getenv("KUBERNETES") == "true" { - helper.DeleteNamespace(namespace) - os.Unsetenv("KUBECONFIG") - } else { - helper.DeleteProject(namespace) - } + cliRunner.DeleteNamespaceProject(namespace) + os.Unsetenv("KUBECONFIG") helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index b5ca3b3b88b..9e11f1b3d0e 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -14,32 +14,35 @@ var _ = Describe("odo devfile registry command tests", func() { var project string var context string var currentWorkingDirectory string + var cliRunner helper.CliRunner const registryName string = "RegistryName" const addRegistryURL string = "https://raw.githubusercontent.com/GeekArthur/registry/master" const updateRegistryURL string = "http://www.example.com/update" + // Using program commmand according to cliRunner in devfile + if os.Getenv("KUBERNETES") == "true" { + cliRunner = helper.NewKubectlRunner("kubectl") + } else { + cliRunner = helper.NewOcRunner("oc") + } + // This is run after every Spec (It) var _ = BeforeEach(func() { SetDefaultEventuallyTimeout(10 * time.Minute) context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - project = helper.CreateRandNamespace() - } else { - project = helper.CreateRandProject() - } + homeDir := helper.GetUserHomeDir() + helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) }) // This is run after every Spec (It) var _ = AfterEach(func() { - if os.Getenv("KUBERNETES") == "true" { - helper.DeleteNamespace(project) - } else { - helper.DeleteProject(project) - } + cliRunner.DeleteNamespaceProject(project) + os.Unsetenv("KUBECONFIG") helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) }) diff --git a/tests/integration/devfile/cmd_devfile_watch_test.go b/tests/integration/devfile/cmd_devfile_watch_test.go index 4b2c560f09b..0eb402ac1b4 100644 --- a/tests/integration/devfile/cmd_devfile_watch_test.go +++ b/tests/integration/devfile/cmd_devfile_watch_test.go @@ -17,7 +17,6 @@ var _ = Describe("odo devfile watch command tests", func() { var context string var cmpName string var currentWorkingDirectory string - var cliRunner helper.CliRunner // Setup up state for each test spec @@ -29,8 +28,8 @@ var _ = Describe("odo devfile watch command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) if os.Getenv("KUBERNETES") == "true" { homeDir := helper.GetUserHomeDir() - _ = helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - namespace = helper.CreateRandNamespace() + helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + namespace = cliRunner.CreateRandNamespaceProject() cliRunner = helper.NewKubectlRunner("kubectl") } else { namespace = helper.CreateRandProject() @@ -47,12 +46,8 @@ var _ = Describe("odo devfile watch command tests", func() { // Clean up after the test // This is run after every Spec (It) var _ = AfterEach(func() { - if os.Getenv("KUBERNETES") == "true" { - helper.DeleteNamespace(namespace) - os.Unsetenv("KUBECONFIG") - } else { - helper.DeleteProject(namespace) - } + cliRunner.DeleteNamespaceProject(namespace) + os.Unsetenv("KUBECONFIG") helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") From e7f8f8ccefb6e312d32c4eeecff77aa862604391 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Fri, 15 May 2020 12:22:42 +0530 Subject: [PATCH 5/9] Added checks for CI to copy kubeconfig to temp dir --- tests/helper/helper_generic.go | 11 +++ tests/helper/kubernetes_utils.go | 4 +- .../devfile/cmd_devfile_catalog_test.go | 3 +- .../devfile/cmd_devfile_push_test.go | 3 +- .../devfile/cmd_devfile_registry_test.go | 3 +- .../devfile/cmd_devfile_watch_test.go | 83 +++++-------------- 6 files changed, 37 insertions(+), 70 deletions(-) diff --git a/tests/helper/helper_generic.go b/tests/helper/helper_generic.go index 09fa06ebc62..746aa7f4f8e 100644 --- a/tests/helper/helper_generic.go +++ b/tests/helper/helper_generic.go @@ -7,6 +7,7 @@ import ( "math/rand" "os" "os/exec" + "path/filepath" "strings" "time" @@ -167,3 +168,13 @@ func GetUserHomeDir() string { Expect(err).NotTo(HaveOccurred()) return homeDir } + +// LocalKubeconfigSet checks for the running CI and sets the KUBECONFIG to the temporary config directory respectively +func LocalKubeconfigSet(context string) { + originalKubeCfg := os.Getenv("KUBECONFIG") + if originalKubeCfg == "" { + homeDir := GetUserHomeDir() + originalKubeCfg = filepath.Join(homeDir, ".kube", "config") + } + copyKubeConfigFile(originalKubeCfg, filepath.Join(context, "config")) +} diff --git a/tests/helper/kubernetes_utils.go b/tests/helper/kubernetes_utils.go index 14024c0b6b1..beab19a0c55 100644 --- a/tests/helper/kubernetes_utils.go +++ b/tests/helper/kubernetes_utils.go @@ -6,8 +6,8 @@ import ( . "github.com/onsi/gomega" ) -// CopyKubeConfigFile copies default kubeconfig file into current temporary context config file -func CopyKubeConfigFile(kubeConfigFile, tempConfigFile string) { +// copyKubeConfigFile copies default kubeconfig file into current temporary context config file +func copyKubeConfigFile(kubeConfigFile, tempConfigFile string) { info, err := os.Stat(kubeConfigFile) Expect(err).NotTo(HaveOccurred()) err = copyFile(kubeConfigFile, tempConfigFile, info) diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index 184e05fd34c..568a52c3dee 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -29,8 +29,7 @@ var _ = Describe("odo devfile catalog command tests", func() { context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - homeDir := helper.GetUserHomeDir() - helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + helper.LocalKubeconfigSet(context) project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index c408214ecbe..eec97a8874d 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -34,8 +34,7 @@ var _ = Describe("odo devfile push command tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - homeDir := helper.GetUserHomeDir() - helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + helper.LocalKubeconfigSet(context) namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() cmpName = helper.RandString(6) diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index 9e11f1b3d0e..120d8ac9198 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -32,8 +32,7 @@ var _ = Describe("odo devfile registry command tests", func() { context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - homeDir := helper.GetUserHomeDir() - helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) + helper.LocalKubeconfigSet(context) project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) diff --git a/tests/integration/devfile/cmd_devfile_watch_test.go b/tests/integration/devfile/cmd_devfile_watch_test.go index 0eb402ac1b4..151d2ee2fbc 100644 --- a/tests/integration/devfile/cmd_devfile_watch_test.go +++ b/tests/integration/devfile/cmd_devfile_watch_test.go @@ -9,16 +9,19 @@ import ( . "github.com/onsi/gomega" "github.com/openshift/odo/tests/helper" - "github.com/openshift/odo/tests/integration/devfile/utils" ) var _ = Describe("odo devfile watch command tests", func() { - var namespace string - var context string - var cmpName string - var currentWorkingDirectory string + var namespace, context, currentWorkingDirectory, originalKubeconfig string var cliRunner helper.CliRunner + // Using program commmand according to cliRunner in devfile + if os.Getenv("KUBERNETES") == "true" { + cliRunner = helper.NewKubectlRunner("kubectl") + } else { + cliRunner = helper.NewOcRunner("oc") + } + // Setup up state for each test spec // create new project (not set as active) and new context directory for each test spec // This is run after every Spec (It) @@ -26,35 +29,29 @@ var _ = Describe("odo devfile watch command tests", func() { SetDefaultEventuallyTimeout(10 * time.Minute) context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) - if os.Getenv("KUBERNETES") == "true" { - homeDir := helper.GetUserHomeDir() - helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config")) - namespace = cliRunner.CreateRandNamespaceProject() - cliRunner = helper.NewKubectlRunner("kubectl") - } else { - namespace = helper.CreateRandProject() - cliRunner = helper.NewOcRunner("oc") - } + originalKubeconfig = os.Getenv("KUBECONFIG") + helper.LocalKubeconfigSet(context) + namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() - cmpName = helper.RandString(6) helper.Chdir(context) - - // Set experimental mode to true - helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") }) // Clean up after the test // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(namespace) - os.Unsetenv("KUBECONFIG") helper.Chdir(currentWorkingDirectory) + err := os.Setenv("KUBECONFIG", originalKubeconfig) + Expect(err).NotTo(HaveOccurred()) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") }) Context("when running help for watch command", func() { It("should display the help", func() { + // Devfile push requires experimental mode to be set + helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") + appHelp := helper.CmdShouldPass("odo", "watch", "-h") Expect(appHelp).To(ContainSubstring("Watch for changes")) }) @@ -62,6 +59,8 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing watch without pushing a devfile component", func() { It("should fail", func() { + // Devfile push requires experimental mode to be set + helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") cmpName := helper.RandString(6) helper.Chdir(currentWorkingDirectory) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, "--context", context, cmpName) @@ -72,6 +71,8 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing watch without a valid devfile", func() { It("should fail", func() { + // Devfile push requires experimental mode to be set + helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") output := helper.CmdShouldFail("odo", "watch", "--devfile", "fake-devfile.yaml") Expect(output).To(ContainSubstring("The current directory does not represent an odo component")) }) @@ -79,51 +80,9 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing odo watch with devfile flag without experimental mode", func() { It("should fail", func() { - helper.CmdShouldPass("odo", "preference", "set", "Experimental", "false", "-f") - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) - helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context) output := helper.CmdShouldFail("odo", "watch", "--devfile", filepath.Join(context, "devfile.yaml")) Expect(output).To(ContainSubstring("Error: unknown flag: --devfile")) }) }) - - Context("when executing odo watch after odo push", func() { - It("should listen for file changes", func() { - helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) - - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) - helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) - - output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) - Expect(output).To(ContainSubstring("Changes successfully pushed to component")) - - watchFlag := "" - odoV2Watch := utils.OdoV2Watch{ - CmpName: cmpName, - StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"}, - } - // odo watch and validate - utils.OdoWatch(utils.OdoV1Watch{}, odoV2Watch, namespace, context, watchFlag, cliRunner, "kube") - }) - }) - - Context("when executing odo watch after odo push with custom commands", func() { - It("should listen for file changes", func() { - helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) - - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) - helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) - - output := helper.CmdShouldPass("odo", "push", "--build-command", "build", "--run-command", "run", "--devfile", "devfile.yaml", "--project", namespace) - Expect(output).To(ContainSubstring("Changes successfully pushed to component")) - - watchFlag := "--build-command build --run-command run" - odoV2Watch := utils.OdoV2Watch{ - CmpName: cmpName, - StringsToBeMatched: []string{"Executing build command", "Executing run command"}, - } - // odo watch and validate - utils.OdoWatch(utils.OdoV1Watch{}, odoV2Watch, namespace, context, watchFlag, cliRunner, "kube") - }) - }) }) From 620499cb14b86d93040c16cd0a58ffb6521785f4 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Tue, 19 May 2020 12:47:49 +0530 Subject: [PATCH 6/9] Skipping Kubeconfig set to temporary config file for prow --- tests/helper/helper_generic.go | 2 +- tests/integration/devfile/cmd_devfile_catalog_test.go | 10 ++++++++-- tests/integration/devfile/cmd_devfile_push_test.go | 9 +++++++-- tests/integration/devfile/cmd_devfile_registry_test.go | 10 ++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/helper/helper_generic.go b/tests/helper/helper_generic.go index 746aa7f4f8e..7918aa23b43 100644 --- a/tests/helper/helper_generic.go +++ b/tests/helper/helper_generic.go @@ -169,7 +169,7 @@ func GetUserHomeDir() string { return homeDir } -// LocalKubeconfigSet checks for the running CI and sets the KUBECONFIG to the temporary config directory respectively +// LocalKubeconfigSet sets the KUBECONFIG to the temporary config file func LocalKubeconfigSet(context string) { originalKubeCfg := os.Getenv("KUBECONFIG") if originalKubeCfg == "" { diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index 568a52c3dee..bcf97acaa0b 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -29,7 +29,11 @@ var _ = Describe("odo devfile catalog command tests", func() { context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - helper.LocalKubeconfigSet(context) + + // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 + if os.Getenv("CI") != "openshift" { + helper.LocalKubeconfigSet(context) + } project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) @@ -38,7 +42,9 @@ var _ = Describe("odo devfile catalog command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - os.Unsetenv("KUBECONFIG") + if os.Getenv("CI") != "openshift" { + os.Unsetenv("KUBECONFIG") + } helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index eec97a8874d..c5d79ebef7e 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -34,7 +34,10 @@ var _ = Describe("odo devfile push command tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - helper.LocalKubeconfigSet(context) + // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 + if os.Getenv("CI") != "openshift" { + helper.LocalKubeconfigSet(context) + } namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() cmpName = helper.RandString(6) @@ -45,7 +48,9 @@ var _ = Describe("odo devfile push command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(namespace) - os.Unsetenv("KUBECONFIG") + if os.Getenv("CI") != "openshift" { + os.Unsetenv("KUBECONFIG") + } helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index 120d8ac9198..7d4297832b8 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -32,7 +32,11 @@ var _ = Describe("odo devfile registry command tests", func() { context = helper.CreateNewContext() os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - helper.LocalKubeconfigSet(context) + + // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 + if os.Getenv("CI") != "openshift" { + helper.LocalKubeconfigSet(context) + } project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) @@ -41,7 +45,9 @@ var _ = Describe("odo devfile registry command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - os.Unsetenv("KUBECONFIG") + if os.Getenv("CI") != "openshift" { + os.Unsetenv("KUBECONFIG") + } helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) }) From 46da56c07224ccfd5f19a86901539662bdd2e8de Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Tue, 19 May 2020 16:11:07 +0530 Subject: [PATCH 7/9] Set Kubeconfig in temporary config file on kubernetes cluster only --- .travis.yml | 2 +- tests/integration/devfile/cmd_devfile_catalog_test.go | 5 ++--- tests/integration/devfile/cmd_devfile_push_test.go | 5 ++--- tests/integration/devfile/cmd_devfile_registry_test.go | 5 ++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f661fa212c..f3ce9b9b469 100644 --- a/.travis.yml +++ b/.travis.yml @@ -192,4 +192,4 @@ jobs: - export KUBERNETES=true - travis_wait make test-cmd-devfile-catalog - travis_wait make test-cmd-devfile-watch - - travis_wait make test-cmd-devfile-push \ No newline at end of file + - travis_wait make test-cmd-devfile-push diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index bcf97acaa0b..f78b96f4053 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -30,8 +30,7 @@ var _ = Describe("odo devfile catalog command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { helper.LocalKubeconfigSet(context) } project = cliRunner.CreateRandNamespaceProject() @@ -42,7 +41,7 @@ var _ = Describe("odo devfile catalog command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { os.Unsetenv("KUBECONFIG") } helper.Chdir(currentWorkingDirectory) diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index c5d79ebef7e..f9aba0d0abd 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -34,8 +34,7 @@ var _ = Describe("odo devfile push command tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { helper.LocalKubeconfigSet(context) } namespace = cliRunner.CreateRandNamespaceProject() @@ -48,7 +47,7 @@ var _ = Describe("odo devfile push command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(namespace) - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { os.Unsetenv("KUBECONFIG") } helper.Chdir(currentWorkingDirectory) diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index 7d4297832b8..e093cc8b2ca 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -33,8 +33,7 @@ var _ = Describe("odo devfile registry command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - // Skipping the KUBECONFIG set to a temporary config for prow due to https://github.com/openshift/odo/issues/3203 - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { helper.LocalKubeconfigSet(context) } project = cliRunner.CreateRandNamespaceProject() @@ -45,7 +44,7 @@ var _ = Describe("odo devfile registry command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - if os.Getenv("CI") != "openshift" { + if os.Getenv("KUBERNETES") == "true" { os.Unsetenv("KUBECONFIG") } helper.Chdir(currentWorkingDirectory) From 0a90a79b0857307a5eb4e5332b474eb2c74cde02 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Wed, 27 May 2020 14:21:17 +0530 Subject: [PATCH 8/9] Fixes Kubeconfig code sync --- tests/helper/kubernetes_utils.go | 3 + .../devfile/cmd_devfile_catalog_test.go | 14 ++--- .../devfile/cmd_devfile_push_test.go | 12 ++-- .../devfile/cmd_devfile_registry_test.go | 14 ++--- .../devfile/cmd_devfile_watch_test.go | 59 +++++++++++++++---- 5 files changed, 67 insertions(+), 35 deletions(-) diff --git a/tests/helper/kubernetes_utils.go b/tests/helper/kubernetes_utils.go index beab19a0c55..25674778573 100644 --- a/tests/helper/kubernetes_utils.go +++ b/tests/helper/kubernetes_utils.go @@ -1,8 +1,10 @@ package helper import ( + "fmt" "os" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -13,4 +15,5 @@ func copyKubeConfigFile(kubeConfigFile, tempConfigFile string) { err = copyFile(kubeConfigFile, tempConfigFile, info) Expect(err).NotTo(HaveOccurred()) os.Setenv("KUBECONFIG", tempConfigFile) + fmt.Fprintf(GinkgoWriter, "Setting KUBECONFIG=%s\n", tempConfigFile) } diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index f78b96f4053..4aa8f911db5 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -11,9 +11,7 @@ import ( ) var _ = Describe("odo devfile catalog command tests", func() { - var project string - var context string - var currentWorkingDirectory string + var project, context, currentWorkingDirectory, originalKubeconfig string var cliRunner helper.CliRunner // Using program commmand according to cliRunner in devfile @@ -30,9 +28,8 @@ var _ = Describe("odo devfile catalog command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - helper.LocalKubeconfigSet(context) - } + originalKubeconfig = os.Getenv("KUBECONFIG") + helper.LocalKubeconfigSet(context) project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) @@ -41,10 +38,9 @@ var _ = Describe("odo devfile catalog command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - if os.Getenv("KUBERNETES") == "true" { - os.Unsetenv("KUBECONFIG") - } helper.Chdir(currentWorkingDirectory) + err := os.Setenv("KUBECONFIG", originalKubeconfig) + Expect(err).NotTo(HaveOccurred()) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") }) diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index f9aba0d0abd..dde3fde2127 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -14,7 +14,7 @@ import ( ) var _ = Describe("odo devfile push command tests", func() { - var namespace, context, cmpName, currentWorkingDirectory string + var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string var sourcePath = "/projects/nodejs-web-app" var cliRunner helper.CliRunner @@ -34,9 +34,8 @@ var _ = Describe("odo devfile push command tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - helper.LocalKubeconfigSet(context) - } + originalKubeconfig = os.Getenv("KUBECONFIG") + helper.LocalKubeconfigSet(context) namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() cmpName = helper.RandString(6) @@ -47,10 +46,9 @@ var _ = Describe("odo devfile push command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(namespace) - if os.Getenv("KUBERNETES") == "true" { - os.Unsetenv("KUBECONFIG") - } helper.Chdir(currentWorkingDirectory) + err := os.Setenv("KUBECONFIG", originalKubeconfig) + Expect(err).NotTo(HaveOccurred()) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") }) diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index e093cc8b2ca..27fbc569dbc 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -11,9 +11,7 @@ import ( ) var _ = Describe("odo devfile registry command tests", func() { - var project string - var context string - var currentWorkingDirectory string + var project, context, currentWorkingDirectory, originalKubeconfig string var cliRunner helper.CliRunner const registryName string = "RegistryName" const addRegistryURL string = "https://raw.githubusercontent.com/GeekArthur/registry/master" @@ -33,9 +31,8 @@ var _ = Describe("odo devfile registry command tests", func() { os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml")) helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - if os.Getenv("KUBERNETES") == "true" { - helper.LocalKubeconfigSet(context) - } + originalKubeconfig = os.Getenv("KUBECONFIG") + helper.LocalKubeconfigSet(context) project = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() helper.Chdir(context) @@ -44,10 +41,9 @@ var _ = Describe("odo devfile registry command tests", func() { // This is run after every Spec (It) var _ = AfterEach(func() { cliRunner.DeleteNamespaceProject(project) - if os.Getenv("KUBERNETES") == "true" { - os.Unsetenv("KUBECONFIG") - } helper.Chdir(currentWorkingDirectory) + err := os.Setenv("KUBECONFIG", originalKubeconfig) + Expect(err).NotTo(HaveOccurred()) helper.DeleteDir(context) }) diff --git a/tests/integration/devfile/cmd_devfile_watch_test.go b/tests/integration/devfile/cmd_devfile_watch_test.go index 151d2ee2fbc..cf3a9dfbcea 100644 --- a/tests/integration/devfile/cmd_devfile_watch_test.go +++ b/tests/integration/devfile/cmd_devfile_watch_test.go @@ -9,10 +9,11 @@ import ( . "github.com/onsi/gomega" "github.com/openshift/odo/tests/helper" + "github.com/openshift/odo/tests/integration/devfile/utils" ) var _ = Describe("odo devfile watch command tests", func() { - var namespace, context, currentWorkingDirectory, originalKubeconfig string + var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string var cliRunner helper.CliRunner // Using program commmand according to cliRunner in devfile @@ -33,7 +34,11 @@ var _ = Describe("odo devfile watch command tests", func() { helper.LocalKubeconfigSet(context) namespace = cliRunner.CreateRandNamespaceProject() currentWorkingDirectory = helper.Getwd() + cmpName = helper.RandString(6) helper.Chdir(context) + + // Set experimental mode to true + helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") }) // Clean up after the test @@ -49,9 +54,6 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when running help for watch command", func() { It("should display the help", func() { - // Devfile push requires experimental mode to be set - helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - appHelp := helper.CmdShouldPass("odo", "watch", "-h") Expect(appHelp).To(ContainSubstring("Watch for changes")) }) @@ -59,9 +61,6 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing watch without pushing a devfile component", func() { It("should fail", func() { - // Devfile push requires experimental mode to be set - helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") - cmpName := helper.RandString(6) helper.Chdir(currentWorkingDirectory) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, "--context", context, cmpName) output := helper.CmdShouldFail("odo", "watch", "--context", context) @@ -71,8 +70,6 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing watch without a valid devfile", func() { It("should fail", func() { - // Devfile push requires experimental mode to be set - helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") output := helper.CmdShouldFail("odo", "watch", "--devfile", "fake-devfile.yaml") Expect(output).To(ContainSubstring("The current directory does not represent an odo component")) }) @@ -80,9 +77,51 @@ var _ = Describe("odo devfile watch command tests", func() { Context("when executing odo watch with devfile flag without experimental mode", func() { It("should fail", func() { - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context) + helper.CmdShouldPass("odo", "preference", "set", "Experimental", "false", "-f") + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) output := helper.CmdShouldFail("odo", "watch", "--devfile", filepath.Join(context, "devfile.yaml")) Expect(output).To(ContainSubstring("Error: unknown flag: --devfile")) }) }) + + Context("when executing odo watch after odo push", func() { + It("should listen for file changes", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + + output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace) + Expect(output).To(ContainSubstring("Changes successfully pushed to component")) + + watchFlag := "" + odoV2Watch := utils.OdoV2Watch{ + CmpName: cmpName, + StringsToBeMatched: []string{"Executing devbuild command", "Executing devrun command"}, + } + // odo watch and validate + utils.OdoWatch(utils.OdoV1Watch{}, odoV2Watch, namespace, context, watchFlag, cliRunner, "kube") + }) + }) + + Context("when executing odo watch after odo push with custom commands", func() { + It("should listen for file changes", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + + output := helper.CmdShouldPass("odo", "push", "--build-command", "build", "--run-command", "run", "--devfile", "devfile.yaml", "--project", namespace) + Expect(output).To(ContainSubstring("Changes successfully pushed to component")) + + watchFlag := "--build-command build --run-command run" + odoV2Watch := utils.OdoV2Watch{ + CmpName: cmpName, + StringsToBeMatched: []string{"Executing build command", "Executing run command"}, + } + // odo watch and validate + utils.OdoWatch(utils.OdoV1Watch{}, odoV2Watch, namespace, context, watchFlag, cliRunner, "kube") + }) + }) }) From 3cd20de6b8b897d1b6837aec4c04b52e0085b314 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Wed, 3 Jun 2020 12:57:40 +0530 Subject: [PATCH 9/9] Separate out function for getting cliRunner --- tests/helper/helper_generic.go | 8 ++++++++ tests/integration/devfile/cmd_devfile_catalog_test.go | 7 +------ tests/integration/devfile/cmd_devfile_push_test.go | 7 +------ tests/integration/devfile/cmd_devfile_registry_test.go | 7 +------ tests/integration/devfile/cmd_devfile_watch_test.go | 7 +------ 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/helper/helper_generic.go b/tests/helper/helper_generic.go index 7918aa23b43..ee677a3c75a 100644 --- a/tests/helper/helper_generic.go +++ b/tests/helper/helper_generic.go @@ -178,3 +178,11 @@ func LocalKubeconfigSet(context string) { } copyKubeConfigFile(originalKubeCfg, filepath.Join(context, "config")) } + +// GetCliRunner gets the running cli against Kubernetes or OpenShift +func GetCliRunner() CliRunner { + if os.Getenv("KUBERNETES") == "true" { + return NewKubectlRunner("kubectl") + } + return NewOcRunner("oc") +} diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index 4aa8f911db5..c1c1c12320c 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -12,14 +12,9 @@ import ( var _ = Describe("odo devfile catalog command tests", func() { var project, context, currentWorkingDirectory, originalKubeconfig string - var cliRunner helper.CliRunner // Using program commmand according to cliRunner in devfile - if os.Getenv("KUBERNETES") == "true" { - cliRunner = helper.NewKubectlRunner("kubectl") - } else { - cliRunner = helper.NewOcRunner("oc") - } + cliRunner := helper.GetCliRunner() // This is run after every Spec (It) var _ = BeforeEach(func() { diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index dde3fde2127..d9c4f13e51f 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -16,14 +16,9 @@ import ( var _ = Describe("odo devfile push command tests", func() { var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string var sourcePath = "/projects/nodejs-web-app" - var cliRunner helper.CliRunner // Using program commmand according to cliRunner in devfile - if os.Getenv("KUBERNETES") == "true" { - cliRunner = helper.NewKubectlRunner("kubectl") - } else { - cliRunner = helper.NewOcRunner("oc") - } + cliRunner := helper.GetCliRunner() // This is run after every Spec (It) var _ = BeforeEach(func() { diff --git a/tests/integration/devfile/cmd_devfile_registry_test.go b/tests/integration/devfile/cmd_devfile_registry_test.go index 27fbc569dbc..44dc90ef920 100644 --- a/tests/integration/devfile/cmd_devfile_registry_test.go +++ b/tests/integration/devfile/cmd_devfile_registry_test.go @@ -12,17 +12,12 @@ import ( var _ = Describe("odo devfile registry command tests", func() { var project, context, currentWorkingDirectory, originalKubeconfig string - var cliRunner helper.CliRunner const registryName string = "RegistryName" const addRegistryURL string = "https://raw.githubusercontent.com/GeekArthur/registry/master" const updateRegistryURL string = "http://www.example.com/update" // Using program commmand according to cliRunner in devfile - if os.Getenv("KUBERNETES") == "true" { - cliRunner = helper.NewKubectlRunner("kubectl") - } else { - cliRunner = helper.NewOcRunner("oc") - } + cliRunner := helper.GetCliRunner() // This is run after every Spec (It) var _ = BeforeEach(func() { diff --git a/tests/integration/devfile/cmd_devfile_watch_test.go b/tests/integration/devfile/cmd_devfile_watch_test.go index cf3a9dfbcea..0ef2ad0b167 100644 --- a/tests/integration/devfile/cmd_devfile_watch_test.go +++ b/tests/integration/devfile/cmd_devfile_watch_test.go @@ -14,14 +14,9 @@ import ( var _ = Describe("odo devfile watch command tests", func() { var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string - var cliRunner helper.CliRunner // Using program commmand according to cliRunner in devfile - if os.Getenv("KUBERNETES") == "true" { - cliRunner = helper.NewKubectlRunner("kubectl") - } else { - cliRunner = helper.NewOcRunner("oc") - } + cliRunner := helper.GetCliRunner() // Setup up state for each test spec // create new project (not set as active) and new context directory for each test spec