Skip to content

Commit

Permalink
Add some tests for manifest deploy part of odo deploy command (#13)
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Groeger <groeges@uk.ibm.com>
  • Loading branch information
groeges authored Jul 1, 2020
1 parent 32beaf9 commit fe7dbaa
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
)

const (
DeployWaitTimeout = 30 * time.Second
DeployWaitTimeout = 60 * time.Second
)

// New instantiantes a component adapter
Expand Down
40 changes: 40 additions & 0 deletions tests/examples/source/devfilesV2/nodejs/devfile-no-manifest.yaml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 57 additions & 5 deletions tests/integration/devfile/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package devfile

import (
"fmt"
"os"
"path/filepath"
"time"
Expand All @@ -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)
Expand All @@ -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"))
})
})
Expand All @@ -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"))
})
})
Expand All @@ -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)))
})
})
})

0 comments on commit fe7dbaa

Please sign in to comment.