From 9d13836b8a3dc2a66ae155245541ad22afa34f4e Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Mon, 17 Apr 2023 22:18:26 +0530 Subject: [PATCH] Use java devfile for odo dev testing and nodejs for debugging Signed-off-by: Parthvi Vala --- tests/e2escenarios/e2e_devfile_test.go | 82 ----------- tests/e2escenarios/e2e_test.go | 133 +++++++++++++++--- .../devfiles/springboot/devfile-deploy.yaml | 102 ++++++++++++++ .../source/devfiles/springboot/devfile.yaml | 2 +- 4 files changed, 215 insertions(+), 104 deletions(-) delete mode 100644 tests/e2escenarios/e2e_devfile_test.go create mode 100644 tests/examples/source/devfiles/springboot/devfile-deploy.yaml diff --git a/tests/e2escenarios/e2e_devfile_test.go b/tests/e2escenarios/e2e_devfile_test.go deleted file mode 100644 index 3e204a99c25..00000000000 --- a/tests/e2escenarios/e2e_devfile_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package e2escenarios - -import ( - "github.com/redhat-developer/odo/tests/helper" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -// Test Objective: -// Test ODO devfile support features - -// Scope: -// Test debug support for the following components, making use of starter projects define in the corresponding devfile: -// - nodejs -// - java-springboot -// - java-quarkus -// - java-maven - -var _ = Describe("odo devfile supported tests", func() { - var componentName, projectDirPath string - var projectDir = "/projectDir" - var commonVar helper.CommonVar - - // This is run before every Spec (It) - var _ = BeforeEach(func() { - commonVar = helper.CommonBeforeEach() - componentName = helper.RandString(6) - helper.Chdir(commonVar.Context) - projectDirPath = commonVar.Context + projectDir - helper.MakeDir(projectDirPath) - helper.Chdir(projectDirPath) - }) - - // This is run after every Spec (It) - var _ = AfterEach(func() { - helper.CommonAfterEach(commonVar) - }) - - createStarterProjAndSetDebug := func(component, starter string) { - workingDir := helper.Getwd() - defer helper.Chdir(workingDir) - helper.Chdir(projectDirPath) - helper.Cmd("odo", "init", "--name", componentName, "--devfile", component, "--starter", starter).ShouldPass() - session, _, _, _, err := helper.StartDevMode(helper.DevSessionOpts{}) - Expect(err).ToNot(HaveOccurred()) - session.Stop() - session.WaitEnd() - - // stopChannel := make(chan bool) - // go func() { - // helper.Cmd("odo", "debug", "port-forward", "--local-port", debugLocalPort, "--context", projectDirPath).WithTerminate(60*time.Second, stopChannel).ShouldRun() - // }() - // - // // Make sure that the debug information output, outputs correctly. - // // We do *not* check the json output since the debugProcessID will be different each time. - // helper.WaitForCmdOut("odo", []string{"debug", "info", "-o", "json", "--context", projectDirPath}, 1, false, func(output string) bool { - // if strings.Contains(output, `"kind": "OdoDebugInfo"`) && - // strings.Contains(output, fmt.Sprintf(`"localPort": %s`, debugLocalPort)) { - // return true - // } - // return false - // }) - // stopChannel <- true - } - - Context("odo debug support for devfile components", func() { - It("Verify output debug information for nodeJS debug works", func() { - createStarterProjAndSetDebug("nodejs", "nodejs-starter") - }) - It("Verify output debug information for java-springboot works", func() { - createStarterProjAndSetDebug("java-springboot", "springbootproject") - }) - It("Verify output debug information for java-quarkus debug works", func() { - createStarterProjAndSetDebug("java-quarkus", "community") - }) - It("Verify output debug information for java-maven debug works", func() { - createStarterProjAndSetDebug("java-maven", "springbootproject") - }) - }) - -}) diff --git a/tests/e2escenarios/e2e_test.go b/tests/e2escenarios/e2e_test.go index 1505447f80d..96000b2ae4b 100644 --- a/tests/e2escenarios/e2e_test.go +++ b/tests/e2escenarios/e2e_test.go @@ -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" @@ -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, "") @@ -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() @@ -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() @@ -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", diff --git a/tests/examples/source/devfiles/springboot/devfile-deploy.yaml b/tests/examples/source/devfiles/springboot/devfile-deploy.yaml new file mode 100644 index 00000000000..48c7c74642a --- /dev/null +++ b/tests/examples/source/devfiles/springboot/devfile-deploy.yaml @@ -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 + diff --git a/tests/examples/source/devfiles/springboot/devfile.yaml b/tests/examples/source/devfiles/springboot/devfile.yaml index 99b74ed421d..77f9ef4bfe6 100644 --- a/tests/examples/source/devfiles/springboot/devfile.yaml +++ b/tests/examples/source/devfiles/springboot/devfile.yaml @@ -3,7 +3,7 @@ schemaVersion: 2.2.0 metadata: name: java-spring-boot language: java - projectType: spring + projectType: springboot starterProjects: - name: springbootproject git: