Skip to content

Commit

Permalink
cherry-pick redhat-developer#5116
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Oct 8, 2021
1 parent 885874f commit 78d4397
Show file tree
Hide file tree
Showing 23 changed files with 265 additions and 158 deletions.
61 changes: 61 additions & 0 deletions tests/examples/source/devfiles/nodejs/devfile-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
workingDir: /project
id: test
components:
- container:
endpoints:
- name: http-3000
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
name: runtime
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-prj1-api-abhz
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.0.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
49 changes: 49 additions & 0 deletions tests/examples/source/devfiles/python/devfile-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
commands:
- exec:
commandLine: pip install --user -r requirements.txt
component: py-web
group:
isDefault: true
kind: build
id: pip-install-requirements
- exec:
commandLine: python app.py
component: py-web
group:
isDefault: true
kind: run
workingDir: ${PROJECTS_ROOT}
id: run-app
- exec:
commandLine: pip install --user debugpy && python -m debugpy --listen 0.0.0.0:${DEBUG_PORT}
app.py
component: py-web
group:
kind: debug
workingDir: ${PROJECTS_ROOT}
id: debugpy
components:
- container:
endpoints:
- name: web
targetPort: 8080
image: quay.io/eclipse/che-python-3.7:nightly
mountSources: true
name: py-web
metadata:
description: Python Stack with Python 3.7
displayName: Python
icon: https://www.python.org/static/community_logos/python-logo-generic.svg
language: python
name: python-prj1-api-cajf
projectType: python
tags:
- Python
- pip
version: 1.0.0
schemaVersion: 2.0.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/python-ex
name: python-example
56 changes: 56 additions & 0 deletions tests/examples/source/devfiles/springboot/devfile-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
commands:
- exec:
commandLine: mvn clean -Dmaven.repo.local=/home/user/.m2/repository package -Dmaven.test.skip=true
component: tools
group:
isDefault: true
kind: build
id: build
- exec:
commandLine: mvn -Dmaven.repo.local=/home/user/.m2/repository spring-boot:run
component: tools
group:
isDefault: true
kind: run
id: run
- exec:
commandLine: java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n
-jar target/*.jar
component: tools
group:
isDefault: true
kind: debug
id: debug
components:
- container:
endpoints:
- name: 8080-tcp
targetPort: 8080
image: quay.io/eclipse/che-java11-maven:next
memoryLimit: 768Mi
mountSources: true
volumeMounts:
- name: m2
path: /home/user/.m2
name: tools
- name: m2
volume:
size: 3Gi
metadata:
description: Spring Boot® using Java
displayName: Spring Boot®
globalMemoryLimit: 2674Mi
icon: https://spring.io/images/projects/spring-edf462fec682b9d48cf628eaf9e19521.svg
language: java
name: java-springboot-springboot-zbgd
projectType: spring
tags:
- Java
- Spring
version: 1.1.0
schemaVersion: 2.0.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/springboot-ex.git
name: springbootproject
6 changes: 6 additions & 0 deletions tests/helper/helper_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func CopyManifestFile(fileName, targetDst string) {

}

func GetExamplePath(args ...string) string {
_, filename, _, _ := runtime.Caller(0)
path := append([]string{filepath.Dir(filename), "..", "examples"}, args...)
return filepath.Join(path...)
}

// CopyExampleDevFile copies an example devfile from tests/examples/source/devfiles/<componentName>/devfile.yaml
// into targetDst
func CopyExampleDevFile(devfilePath, targetDst string) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_link_unlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("odo link and unlink command tests", func() {
// createAndPush: creates component, a URL for it and deploys it
var createAndPush = func(compType string, compName string, contextDir string) {
helper.CopyExample(filepath.Join("source", compType), contextDir)
helper.Cmd("odo", "create", compType, compName, "--context", contextDir, "--project", commonVar.Project).ShouldPass()
helper.Cmd("odo", "create", compName, "--context", contextDir, "--project", commonVar.Project, "--devfile", helper.GetExamplePath("source", "devfiles", compType, "devfile-registry.yaml")).ShouldPass()
helper.Cmd("odo", "url", "create", "--port", "8080", "--context", contextDir).ShouldPass()
helper.Cmd("odo", "push", "--context", contextDir).ShouldPass()
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cmd_pref_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = Describe("odo preference and config command tests", func() {
var token string
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.Cmd("odo", "create", "nodejs", "nodejs", "--project", commonVar.Project, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "nodejs", "--project", commonVar.Project, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass()
ocRunner = helper.NewOcRunner("oc")
token = ocRunner.GetToken()
ocRunner.Logout()
Expand Down Expand Up @@ -185,7 +185,7 @@ var _ = Describe("odo preference and config command tests", func() {
// !! Do not test with true because it sends out the telemetry data and messes up the statistics !!
It("should not prompt the user", func() {
helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "false", "-f").ShouldPass()
output := helper.Cmd("odo", "create", "nodejs", "--context", commonVar.Context).ShouldPass().Out()
output := helper.Cmd("odo", "create", "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass().Out()
Expect(output).ToNot(ContainSubstring(promptMessageSubString))
})
})
Expand Down
9 changes: 4 additions & 5 deletions tests/integration/devfile/cmd_devfile_app_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package devfile

import (
"github.com/tidwall/gjson"
"path/filepath"

"github.com/tidwall/gjson"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
Expand Down Expand Up @@ -97,9 +98,8 @@ var _ = Describe("odo devfile app command tests", func() {
storage00 := helper.RandString(4)
url00 := helper.RandString(4)

helper.Cmd("odo", "create", "nodejs", "--project", namespace, component00, "--context", context00, "--app", app0).ShouldPass()
helper.Cmd("odo", "create", "--project", namespace, component00, "--context", context00, "--app", app0, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfileNestedCompCommands.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context00)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfileNestedCompCommands.yaml"), filepath.Join(context00, "devfile.yaml"))
helper.Cmd("odo", "storage", "create", storage00, "--path", "/data", "--size", "1Gi", "--context", context00).ShouldPass()
helper.Cmd("odo", "url", "create", url00, "--port", "3000", "--context", context00, "--host", "com", "--ingress").ShouldPass()
helper.Cmd("odo", "push", "--context", context00).ShouldPass()
Expand Down Expand Up @@ -168,9 +168,8 @@ var _ = Describe("odo devfile app command tests", func() {

// createComponent creates with the given parameters and pushes it
func createComponent(componentName, appName, project, context string) {
helper.Cmd("odo", "create", "nodejs", "--project", project, componentName, "--context", context, "--app", appName).ShouldPass()
helper.Cmd("odo", "create", "--project", project, componentName, "--context", context, "--app", appName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(context, "devfile.yaml"))
helper.Cmd("odo", "push", "--context", context).ShouldPass()
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/devfile/cmd_devfile_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("odo devfile config command tests", func() {

When("a component is created", func() {
BeforeEach(func() {
helper.Cmd("odo", "create", "nodejs").ShouldPass()
helper.Cmd("odo", "create", "nodejs", "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass()
})

When("executing config view", func() {
Expand Down
15 changes: 5 additions & 10 deletions tests/integration/devfile/cmd_devfile_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ var _ = Describe("odo devfile debug command tests", func() {

Context("odo debug on a nodejs:latest component", func() {
It("check that machine output debug information works", func() {
helper.Cmd("odo", "create", "nodejs", "--project", commonVar.Project, componentName, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "--project", commonVar.Project, componentName, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.Cmd("odo", "push", "--debug", "--context", commonVar.Context).ShouldPass()

httpPort, err := util.HTTPGetFreePort()
Expand All @@ -59,9 +58,8 @@ var _ = Describe("odo devfile debug command tests", func() {
})

It("should expect a ws connection when tried to connect on default debug port locally", func() {
helper.Cmd("odo", "create", "nodejs", "--project", commonVar.Project, componentName, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "--project", commonVar.Project, componentName, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "push", "--debug", "--context", commonVar.Context).ShouldPass()

Expand Down Expand Up @@ -90,9 +88,8 @@ var _ = Describe("odo devfile debug command tests", func() {

Context("odo debug info should work on a odo component", func() {
It("should start a debug session and run debug info on a running debug session", func() {
helper.Cmd("odo", "create", "nodejs", "nodejs-cmp", "--project", commonVar.Project, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "nodejs-cmp", "--project", commonVar.Project, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.Cmd("odo", "push", "--debug", "--context", commonVar.Context).ShouldPass()

httpPort, err := util.HTTPGetFreePort()
Expand All @@ -115,9 +112,8 @@ var _ = Describe("odo devfile debug command tests", func() {
})

It("should start a debug session and run debug info on a closed debug session", func() {
helper.Cmd("odo", "create", "nodejs", "--project", commonVar.Project, componentName, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "--project", commonVar.Project, componentName, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.Cmd("odo", "push", "--debug", "--context", commonVar.Context).ShouldPass()

httpPort, err := util.HTTPGetFreePort()
Expand Down Expand Up @@ -157,9 +153,8 @@ var _ = Describe("odo devfile debug command tests", func() {

Context("when the debug command throws an error during push", func() {
It("should wait and error out with some log", func() {
helper.Cmd("odo", "create", "nodejs", "--project", commonVar.Project, "--context", commonVar.Context).ShouldPass()
helper.Cmd("odo", "create", "--project", commonVar.Project, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "npm run debug", "npm run debugs")

_, output := helper.Cmd("odo", "push", "--debug", "--context", commonVar.Context).ShouldPass().OutAndErr()
Expand Down
Loading

0 comments on commit 78d4397

Please sign in to comment.