From fe7dbaa382842e49eb6e301ac3f0dff60ee17b85 Mon Sep 17 00:00:00 2001 From: Steve Groeger Date: Wed, 1 Jul 2020 11:28:38 +0100 Subject: [PATCH] Add some tests for manifest deploy part of `odo deploy` command (#13) Signed-off-by: Steven Groeger --- Makefile | 5 ++ .../adapters/kubernetes/component/adapter.go | 2 +- .../nodejs/devfile-no-manifest.yaml | 40 ++++++++++++ .../devfile/cmd_devfile_deploy_test.go | 62 +++++++++++++++++-- 4 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 tests/examples/source/devfilesV2/nodejs/devfile-no-manifest.yaml diff --git a/Makefile b/Makefile index f8b8ab26e2b..9c3e19737dc 100644 --- a/Makefile +++ b/Makefile @@ -208,6 +208,11 @@ test-cmd-devfile-create: test-cmd-devfile-push: ginkgo $(GINKGO_FLAGS) -focus="odo devfile push command tests" tests/integration/devfile/ +# Run odo deploy devfile command tests +.PHONY: test-cmd-devfile-deploy +test-cmd-devfile-deploy: + ginkgo $(GINKGO_FLAGS) -focus="odo devfile deploy command tests" tests/integration/devfile/ + # Run odo push devfile command tests .PHONY: test-cmd-devfile-deploy-delete test-cmd-devfile-deploy-delete: diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index fcf0a2dec67..7984af4dc45 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -41,7 +41,7 @@ import ( ) const ( - DeployWaitTimeout = 30 * time.Second + DeployWaitTimeout = 60 * time.Second ) // New instantiantes a component adapter diff --git a/tests/examples/source/devfilesV2/nodejs/devfile-no-manifest.yaml b/tests/examples/source/devfilesV2/nodejs/devfile-no-manifest.yaml new file mode 100644 index 00000000000..2e513b1bc13 --- /dev/null +++ b/tests/examples/source/devfilesV2/nodejs/devfile-no-manifest.yaml @@ -0,0 +1,40 @@ +schemaVersion: "2.0.0" +metadata: + name: test-devfile + alpha.build-dockerfile: "https://raw.githubusercontent.com/neeraj-laad/nodejs-stack-registry/build-deploy/devfiles/nodejs-basic/build/Dockerfile" +projects: + - name: nodejs-web-app + git: + location: "https://github.com/che-samples/web-nodejs-sample.git" +components: + - container: + image: quay.io/eclipse/che-nodejs10-ubi:nightly + mountSources: true + name: "runtime" + memoryLimit: 1024Mi + env: + - name: FOO + value: "bar" + endpoints: + - name: '3000/tcp' + targetPort: 3000 + # odo not using currently, added to validate JSON Schema + configuration: + protocol: tcp + scheme: http + type: terminal +commands: + - exec: + id: download dependencies + commandLine: "npm install" + component: runtime + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + group: + kind: build + - exec: + id: run the app + commandLine: "nodemon app.js" + component: runtime + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + group: + kind: run diff --git a/tests/integration/devfile/cmd_devfile_deploy_test.go b/tests/integration/devfile/cmd_devfile_deploy_test.go index dcfe383894d..e94e3c13e08 100644 --- a/tests/integration/devfile/cmd_devfile_deploy_test.go +++ b/tests/integration/devfile/cmd_devfile_deploy_test.go @@ -1,6 +1,7 @@ package devfile import ( + "fmt" "os" "path/filepath" "time" @@ -25,9 +26,9 @@ var _ = Describe("odo devfile deploy command tests", func() { helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true") originalKubeconfig = os.Getenv("KUBECONFIG") - imageTag = "image-registry.openshift-image-registry.svc:5000/default/my-nodejs:1.0" helper.LocalKubeconfigSet(context) namespace = cliRunner.CreateRandNamespaceProject() + imageTag = fmt.Sprintf("image-registry.openshift-image-registry.svc:5000/%s/my-nodejs:1.0", namespace) currentWorkingDirectory = helper.Getwd() cmpName = helper.RandString(6) helper.Chdir(context) @@ -48,7 +49,7 @@ var _ = Describe("odo devfile deploy command tests", func() { helper.CmdShouldPass("odo", "url", "create", "--port", "3000") helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) - output := helper.CmdShouldPass("odo", "deploy", "--tag", imageTag, "--devfile", "devfile.yaml") + output := helper.CmdShouldPass("odo", "deploy", "--tag", imageTag) Expect(output).NotTo(ContainSubstring("does not point to a valid Dockerfile")) }) }) @@ -59,10 +60,10 @@ var _ = Describe("odo devfile deploy command tests", func() { helper.CmdShouldPass("odo", "url", "create", "--port", "3000") helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) - err := helper.ReplaceDevfileField("devfile.yaml", "dockerfile", "https://google.com") + err := helper.ReplaceDevfileField("devfile.yaml", "alpha.build-dockerfile", "https://google.com") Expect(err).To(BeNil()) - cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag, "--devfile", "devfile.yaml") + cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag) Expect(cmdOutput).To(ContainSubstring("does not point to a valid Dockerfile")) }) }) @@ -71,8 +72,59 @@ var _ = Describe("odo devfile deploy command tests", func() { It("Should error out with 'dockerfile required for build.'", func() { helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) helper.CmdShouldPass("odo", "url", "create", "--port", "3000") - cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag, "--devfile", "devfile.yaml") + cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag) Expect(cmdOutput).To(ContainSubstring("dockerfile required for build. No 'dockerfile' field found in devfile, or Dockerfile found in project directory")) }) }) + + Context("Verify error when no manifest definition exists in devfile", func() { + It("Should error out with 'Unable to deploy as alpha.deployment-manifest is not defined in devfile.yaml'", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + helper.CmdShouldPass("odo", "url", "create", "--port", "3000") + helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile-no-manifest.yaml"), filepath.Join(context, "devfile.yaml")) + + cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag) + Expect(cmdOutput).To(ContainSubstring("Unable to deploy as alpha.deployment-manifest is not defined in devfile.yaml")) + }) + }) + + Context("Verify error when invalid manifest definition exists in devfile", func() { + It("Should error out with 'Invalid manifest url'", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + helper.CmdShouldPass("odo", "url", "create", "--port", "3000") + helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + err := helper.ReplaceDevfileField("devfile.yaml", "alpha.deployment-manifest", "google.com") + Expect(err).To(BeNil()) + + cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag) + Expect(cmdOutput).To(ContainSubstring("Invalid manifest url")) + }) + }) + + Context("Verify error when manifest file doesnt exist on web", func() { + It("Should error out with 'Unable to download manifest'", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + helper.CmdShouldPass("odo", "url", "create", "--port", "3000") + helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + err := helper.ReplaceDevfileField("devfile.yaml", "alpha.deployment-manifest", "http://github.com/myfile.yaml") + Expect(err).To(BeNil()) + + cmdOutput := helper.CmdShouldFail("odo", "deploy", "--tag", imageTag) + Expect(cmdOutput).To(ContainSubstring("Unable to download manifest")) + }) + }) + + Context("Verify deploy completes when using manifest with deployment/service/route", func() { + It("Should successfully deploy the application and return a URL", func() { + helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName) + helper.CmdShouldPass("odo", "url", "create", "--port", "3000") + helper.CopyExampleDevFile(filepath.Join("source", "devfilesV2", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml")) + err := helper.ReplaceDevfileField("devfile.yaml", "alpha.deployment-manifest", + "https://raw.githubusercontent.com/groeges/devfile-registry/master/devfiles/nodejs/deploy_deployment.yaml") + Expect(err).To(BeNil()) + + cmdOutput := helper.CmdShouldPass("odo", "deploy", "--tag", imageTag) + Expect(cmdOutput).To(ContainSubstring(fmt.Sprintf("URL for application %s-deploy: http://%s-deploy-%s", cmpName, cmpName, namespace))) + }) + }) })