Skip to content

Commit

Permalink
Use java devfile for odo dev testing and nodejs for debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Apr 19, 2023
1 parent 4c21939 commit 9d13836
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 104 deletions.
82 changes: 0 additions & 82 deletions tests/e2escenarios/e2e_devfile_test.go

This file was deleted.

133 changes: 112 additions & 21 deletions tests/e2escenarios/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ var _ = Describe("E2E Test", func() {
})

Context("starting with non-empty Directory", func() {
const (
AppPort = "8080"
AppLocalURL = "http://localhost:8080"
)
var _ = BeforeEach(func() {
helper.Chdir(commonVar.Context)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), commonVar.Context)
})
It("should verify developer workflow from non-empty Directory", func() {
deploymentName := "my-component"
Expand All @@ -200,8 +204,8 @@ var _ = Describe("E2E Test", func() {
_, err := helper.RunInteractive(command, nil, func(ctx helper.InteractiveContext) {

// helper.ExpectString(ctx, "Based on the files in the current directory odo detected")
helper.ExpectString(ctx, "Language: JavaScript")
helper.ExpectString(ctx, "Project type: Node.js")
helper.ExpectString(ctx, "Language: Java")
helper.ExpectString(ctx, "Project type: springboot")
helper.ExpectString(ctx, "Is this correct")

helper.SendLine(ctx, "")
Expand All @@ -223,30 +227,31 @@ var _ = Describe("E2E Test", func() {
// "execute odo dev and add changes to application"
var devSession helper.DevSession
var ports map[string]string

devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
var out []byte
devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js Starter Application!")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js Starter Application!")
Expect(out).ToNot(BeEmpty())
waitRemoteApp(AppLocalURL, "Hello World!")
checkIfDevEnvIsUp(ports[AppPort], "Hello World!")

helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello World!", "Hello updated World!")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from updated Node.js Starter Application!")
checkIfDevEnvIsUp(ports["3000"], "Hello from updated Node.js Starter Application!")
waitRemoteApp(AppLocalURL, "Hello updated World!")
checkIfDevEnvIsUp(ports[AppPort], "Hello updated World!")

// "changes are made to the applications"
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from updated Node.js", "from Node.js app v2")
helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello updated World!", "Hello from an updated World!")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should deploy new changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v2 Starter Application!")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v2 Starter Application!")
waitRemoteApp(AppLocalURL, "Hello from an updated World!")
checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated World!")

// "running odo list"
stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "Node.js", "Dev"})
helper.MatchAllInOutput(stdout, []string{componentName, "springboot", "Dev"})

// "exit dev mode and run odo deploy"
devSession.Stop()
Expand All @@ -262,31 +267,31 @@ var _ = Describe("E2E Test", func() {

// "run odo deploy"
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-deploy.yaml"),
filepath.Join("source", "devfiles", "springboot", "devfile-deploy.yaml"),
path.Join(commonVar.Context, "devfile.yaml"),
helper.DevfileMetadataNameSetter(componentName))
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "nodejs-prj1-api-abhz", componentName)

stdout = helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out()
Expect(stdout).To(ContainSubstring("Your Devfile has been successfully deployed"))

// should deploy new changes
stdout = helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "nodejs", "Deploy"})
helper.MatchAllInOutput(stdout, []string{componentName, "springbooot", "Deploy"})

// start dev mode again
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())

// making changes to the project again
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js app v2", "from Node.js app v3")
helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello from an updated World!", "Hello from an updated v2 World!")

// "should update the changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v3 Starter Application!")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v3 Starter Application!")
waitRemoteApp(AppLocalURL, "Hello from an updated v2 World!")
checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated v2 World!")

// should list both dev,deploy
stdout = helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "nodejs", "Dev", "Deploy"})
helper.MatchAllInOutput(stdout, []string{componentName, "springboot", "Dev", "Deploy"})

// "exit dev mode and run odo deploy"
devSession.Stop()
Expand All @@ -307,6 +312,92 @@ var _ = Describe("E2E Test", func() {
})
})

Context("starting with non-empty Directory test debugging", func() {
// We use a devfile that does not require an external debugger client like in the case of Java Devfiles.
// Node.js is simple and good for testing debugging feature
const (
LocalAppURL = "http://127.0.0.1:3000"
AppPort = "3000"
DebugPort = "5858"
)
var _ = BeforeEach(func() {
helper.Chdir(commonVar.Context)
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
})
It("should verify developer workflow from non-empty Directory", func() {
command := []string{"odo", "init"}
_, err := helper.RunInteractive(command, nil, func(ctx helper.InteractiveContext) {

// helper.ExpectString(ctx, "Based on the files in the current directory odo detected")
helper.ExpectString(ctx, "Language: JavaScript")
helper.ExpectString(ctx, "Project type: Node.js")
helper.ExpectString(ctx, "Is this correct")

helper.SendLine(ctx, "")

helper.ExpectString(ctx, "Select container for which you want to change configuration?")

helper.SendLine(ctx, "")

helper.ExpectString(ctx, "Enter component name")

helper.SendLine(ctx, componentName)

helper.ExpectString(ctx, "Your new component '"+componentName+"' is ready in the current directory")

})
Expect(err).To(BeNil())
Expect(helper.ListFilesInDir(commonVar.Context)).To(ContainElement("devfile.yaml"))

// "execute odo dev and add changes to application"
var devSession helper.DevSession
var ports map[string]string
var out []byte
devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
Expect(out).ToNot(BeEmpty())
waitRemoteApp(LocalAppURL, "Hello from Node.js Starter Application!")
checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp(LocalAppURL, "Hello from updated Node.js Starter Application!")
checkIfDevEnvIsUp(ports[AppPort], "Hello from updated Node.js Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

// "changes are made to the applications"
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from updated Node.js", "from Node.js app v2")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should deploy new changes"
waitRemoteApp(LocalAppURL, "Hello from Node.js app v2 Starter Application!")
checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js app v2 Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

// "running odo list"
stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "Node.js", "Dev"})

// "exit dev mode and run odo deploy"
devSession.Stop()
devSession.WaitEnd()

// all resources should be deleted from the namespace
services := commonVar.CliRunner.GetServices(commonVar.Project)
Expect(services).To(BeEmpty())
pvcs := commonVar.CliRunner.GetAllPVCNames(commonVar.Project)
Expect(pvcs).To(BeEmpty())
pods := commonVar.CliRunner.GetAllPodNames(commonVar.Project)
Expect(pods).To(BeEmpty())

})
})

Context("starting with non-empty Directory add Binding", func() {
sendDataEntry := func(url string) map[string]interface{} {
values := map[string]interface{}{"name": "joe",
Expand Down
102 changes: 102 additions & 0 deletions tests/examples/source/devfiles/springboot/devfile-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
schemaVersion: 2.2.0
metadata:
name: java-spring-boot
language: java
projectType: springboot
starterProjects:
- name: springbootproject
git:
remotes:
origin: "https://github.com/odo-devfiles/springboot-ex.git"
components:
- name: tools
container:
image: registry.access.redhat.com/ubi8/openjdk-11:latest
memoryLimit: 768Mi
command: ['tail']
args: [ '-f', '/dev/null']
mountSources: true
volumeMounts:
- name: springbootpvc
path: /data/cache/.m2
- name: runtime
container:
image: registry.access.redhat.com/ubi8/openjdk-11:latest
memoryLimit: 768Mi
endpoints:
- name: "8080-tcp"
targetPort: 8080
volumeMounts:
- name: springbootpvc
path: /data/cache/.m2
mountSources: true
- name: springbootpvc
volume:
size: 3Gi
ephemeral: true
- name: outerloop-build
image:
imageName: "{{CONTAINER_IMAGE}}"
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
rootRequired: false

- name: outerloop-deploy
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-component
spec:
replicas: 1
selector:
matchLabels:
app: springboot-app
template:
metadata:
labels:
app: springboot-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
resources:
limits:
memory: "128Mi"
cpu: "500m"
commands:
- id: defaultbuild
exec:
component: tools
commandLine: "mvn clean -Dmaven.repo.local=/data/cache/.m2/repository package -Dmaven.test.skip=true"
workingDir: /projects
group:
kind: build
- id: defaultrun
exec:
component: runtime
commandLine: "mvn -Dmaven.repo.local=/data/cache/.m2/repository spring-boot:run"
workingDir: /projects
group:
kind: run
isDefault: true
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy
composite:
commands:
- build-image
- deployk8s
group:
kind: deploy
isDefault: true
variables:
CONTAINER_IMAGE: quay.io/unknown-account/myimage

2 changes: 1 addition & 1 deletion tests/examples/source/devfiles/springboot/devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schemaVersion: 2.2.0
metadata:
name: java-spring-boot
language: java
projectType: spring
projectType: springboot
starterProjects:
- name: springbootproject
git:
Expand Down

0 comments on commit 9d13836

Please sign in to comment.