Skip to content

Commit

Permalink
Update devfile integration tests for port
Browse files Browse the repository at this point in the history
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
  • Loading branch information
maysunfaisal committed Apr 7, 2020
1 parent b7b1c5a commit 08bd146
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 50 deletions.
22 changes: 8 additions & 14 deletions tests/examples/source/devfiles/nodejs/devfile-no-endpoints.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
apiVersion: 1.0.0
metadata:
name: test-devfile
projects:
-
name: nodejs-web-app
source:
type: git
location: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- type: dockerimage
image: quay.io/eclipse/che-nodejs10-ubi:nightly
alias: runtime
memoryLimit: 1024Mi
mountSources: true
commands:
- name: build
actions:
- type: exec
component: runtime
command: "npm install"
workdir: ${CHE_PROJECTS_ROOT}/app
- name: devbuild
actions:
- type: exec
component: runtime
command: "npm install"
workdir: ${CHE_PROJECTS_ROOT}/app
- name: run
actions:
- type: exec
component: runtime
command: "nodemon app.js"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
- name: devrun
actions:
- type: exec
component: runtime
command: "nodemon app.js"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
apiVersion: 1.0.0
metadata:
name: test-devfile
projects:
-
name: nodejs-web-app
source:
type: git
location: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- type: dockerimage
image: quay.io/eclipse/che-nodejs10-ubi:nightly
endpoints:
- name: 'nodejs'
- name: "3000/tcp"
port: 3000
alias: runtime
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
apiVersion: 1.0.0
metadata:
name: test-devfile
projects:
-
name: nodejs-web-app
source:
type: git
location: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- type: dockerimage
image: quay.io/eclipse/che-nodejs10-ubi:nightly
endpoints:
- name: 'nodejs'
- name: "3000/tcp"
port: 3000
alias: runtime
env:
Expand All @@ -19,4 +25,4 @@ commands:
- type: exec
component: runtime
command: "npm install && nodemon app.js"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
16 changes: 11 additions & 5 deletions tests/examples/source/devfiles/nodejs/devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
apiVersion: 1.0.0
metadata:
name: test-devfile
projects:
-
name: nodejs-web-app
source:
type: git
location: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- type: dockerimage
image: quay.io/eclipse/che-nodejs10-ubi:nightly
endpoints:
- name: 'nodejs'
- name: "3000/tcp"
port: 3000
alias: runtime
env:
Expand All @@ -19,22 +25,22 @@ commands:
- type: exec
component: runtime
command: "npm install"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
- name: devbuild
actions:
- type: exec
component: runtime
command: "npm install"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
- name: run
actions:
- type: exec
component: runtime
command: "nodemon app.js"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
- name: devrun
actions:
- type: exec
component: runtime
command: "nodemon app.js"
workdir: ${CHE_PROJECTS_ROOT}/app
workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app
14 changes: 7 additions & 7 deletions tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var _ = Describe("odo devfile push command tests", func() {
var namespace, context, cmpName, currentWorkingDirectory string
var sourcePath = "/projects"
var sourcePath = "/projects/nodejs-web-app"

// TODO: all oc commands in all devfile related test should get replaced by kubectl
// TODO: to goal is not to use "oc"
Expand All @@ -34,7 +34,7 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")

cmpName = helper.RandString(6)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, cmpName)
helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, cmpName)
})

// Clean up after the test
Expand Down Expand Up @@ -65,7 +65,7 @@ var _ = Describe("odo devfile push command tests", func() {
Expect(output).To(ContainSubstring(cmpName))
})

It("Check that odo push works with a devfile", func() {
It("checks that odo push works with a devfile", func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

output := helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
Expand All @@ -88,7 +88,7 @@ var _ = Describe("odo devfile push command tests", func() {
Expect(output).To(ContainSubstring("No file changes detected, skipping build"))

helper.ReplaceString(filepath.Join(context, "app", "app.js"), "Hello World!", "UPDATED!")
output = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
})

It("should be able to create a file, push, delete, then push again propagating the deletions", func() {
Expand Down Expand Up @@ -138,7 +138,7 @@ var _ = Describe("odo devfile push command tests", func() {
podName,
"",
namespace,
[]string{"stat", "/projects/app/app.js"},
[]string{"stat", "/projects/nodejs-web-app/app/app.js"},
func(cmdOp string, err error) bool {
statErr = err
return true
Expand All @@ -152,14 +152,14 @@ var _ = Describe("odo devfile push command tests", func() {
podName,
"",
namespace,
[]string{"stat", "/projects/app/app.js"},
[]string{"stat", "/projects/nodejs-web-app/app/app.js"},
func(cmdOp string, err error) bool {
statErr = err
return true
},
)
Expect(statErr).To(HaveOccurred())
Expect(statErr.Error()).To(ContainSubstring("cannot stat '/projects/app/app.js': No such file or directory"))
Expect(statErr.Error()).To(ContainSubstring("cannot stat '/projects/nodejs-web-app/app/app.js': No such file or directory"))
})

It("should build when no changes are detected in the directory and force flag is enabled", func() {
Expand Down
51 changes: 30 additions & 21 deletions tests/integration/devfile/cmd_devfile_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
)

var _ = Describe("odo devfile url command tests", func() {
var namespace string
var context string
var currentWorkingDirectory string
var namespace, context, componentName, currentWorkingDirectory string

// This is run after every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
Expand All @@ -26,7 +25,12 @@ var _ = Describe("odo devfile url command tests", func() {
currentWorkingDirectory = helper.Getwd()
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")

componentName = helper.RandString(6)
helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, componentName)
})

// Clean up after the test
Expand All @@ -41,22 +45,21 @@ var _ = Describe("odo devfile url command tests", func() {
Context("Listing urls", func() {
It("should list url after push", func() {
var stdout string
componentName := helper.RandString(6)
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"

helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

stdout = helper.CmdShouldFail("odo", "url", "list")
Expect(stdout).To(ContainSubstring("no URLs found"))

stdout = helper.CmdShouldFail("odo", "url", "create", url1, "--port", "8080")
Expect(stdout).To(ContainSubstring("is not exposed"))

stdout = helper.CmdShouldFail("odo", "url", "create", url1, "--port", "9090")
stdout = helper.CmdShouldFail("odo", "url", "create", url1, "--port", "3000")
Expect(stdout).To(ContainSubstring("host must be provided"))

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host)
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml")
helper.WaitForCmdOut("odo", []string{"url", "list"}, 1, false, func(output string) bool {
if strings.Contains(output, url1) {
Expand All @@ -67,22 +70,22 @@ var _ = Describe("odo devfile url command tests", func() {
})
helper.CmdShouldPass("odo", "url", "delete", url1, "-f")
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)

stdout = helper.CmdShouldFail("odo", "url", "list")
Expect(stdout).To(ContainSubstring("no URLs found"))
})

It("should be able to list url in machine readable json format", func() {
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"
componentName := helper.RandString(6)

helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName)
helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host)
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
// odo url list -o json
helper.WaitForCmdOut("odo", []string{"url", "list", "-o", "json"}, 1, true, func(output string) bool {
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"udo.udo.io/v1alpha1","metadata":{},"items":[{"kind":"Ingress","apiVersion":"extensions/v1beta1","metadata":{"name":"%s","creationTimestamp":null},"spec":{"rules":[{"host":"%s","http":{"paths":[{"path":"/","backend":{"serviceName":"%s","servicePort":9090}}]}}]},"status":{"loadBalancer":{}}}]}`, url1, url1+"."+host, componentName)
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"udo.udo.io/v1alpha1","metadata":{},"items":[{"kind":"Ingress","apiVersion":"extensions/v1beta1","metadata":{"name":"%s","creationTimestamp":null},"spec":{"rules":[{"host":"%s","http":{"paths":[{"path":"/","backend":{"serviceName":"%s","servicePort":3000}}]}}]},"status":{"loadBalancer":{}}}]}`, url1, url1+"."+host, componentName)
if strings.Contains(output, url1) {
Expect(desiredURLListJSON).Should(MatchJSON(output))
return true
Expand All @@ -97,14 +100,17 @@ var _ = Describe("odo devfile url command tests", func() {
var stdout string
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"
componentName := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host, "--secure")
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host, "--secure")

stdout = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
helper.MatchAllInOutput(stdout, []string{"https:", url1 + "." + host})

helper.CmdShouldPass("odo", "url", "delete", url1, "-f")
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)

stdout = helper.CmdShouldFail("odo", "url", "list")
Expect(stdout).To(ContainSubstring("no URLs found"))
})
Expand All @@ -113,9 +119,10 @@ var _ = Describe("odo devfile url command tests", func() {
var stdout string
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"
componentName := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName)
stdout = helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host, "--now")

helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

stdout = helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host, "--now")
helper.MatchAllInOutput(stdout, []string{"URL created for component", "http:", url1 + "." + host})
})
})
Expand All @@ -125,12 +132,14 @@ var _ = Describe("odo devfile url command tests", func() {
var stdout string
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"
componentName := helper.RandString(6)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), context)

helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host)

stdout = helper.CmdShouldFail("odo", "url", "describe", url1)
helper.MatchAllInOutput(stdout, []string{url1, "exists in local", "odo push"})

helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
helper.WaitForCmdOut("odo", []string{"url", "describe", url1}, 1, false, func(output string) bool {
if strings.Contains(output, url1) {
Expand Down

0 comments on commit 08bd146

Please sign in to comment.