From 72996e068e3fcdf86378d945678c6e335199e577 Mon Sep 17 00:00:00 2001 From: Maysun J Faisal <31771087+maysunfaisal@users.noreply.github.com> Date: Wed, 1 Jul 2020 08:27:16 -0400 Subject: [PATCH] Update Node devfile tests (#3459) * Update Node test devfile Signed-off-by: Maysun J Faisal * Update node test template check in test Signed-off-by: Maysun J Faisal * resolved devfile debug tests * revert devfile vol changes Signed-off-by: Maysun J Faisal * removed unnecessary git clones * resolved serial debug test * resolved failing docker test Co-authored-by: Girish Ramnani --- docs/public/debugging-using-devfile.adoc | 8 +-- pkg/odo/cli/component/create.go | 4 +- .../devfiles/nodejs/devfile-no-endpoints.yaml | 14 ++-- .../nodejs/devfile-with-debugrun.yaml | 18 ++--- .../devfile-with-multiple-defaults.yaml | 26 ++++---- .../devfiles/nodejs/devfile-with-restart.yaml | 14 ++-- .../devfile-with-sparseCheckoutDir.yaml | 20 +++--- .../devfiles/nodejs/devfile-with-volumes.yaml | 2 +- .../nodejs/devfile-without-devbuild.yaml | 10 +-- .../nodejs/devfile-without-devinit.yaml | 12 ++-- .../source/devfiles/nodejs/devfile.yaml | 22 +++---- .../source/devfiles/nodejs/project/app/app.js | 24 ------- .../devfiles/nodejs/project/package.json | 17 +++-- .../source/devfiles/nodejs/project/server.js | 66 +++++++++++++++++++ .../devfiles/nodejs/project/test/test.js | 21 ++++++ .../devfile/cmd_devfile_catalog_test.go | 2 +- .../devfile/cmd_devfile_create_test.go | 2 +- .../devfile/cmd_devfile_debug_test.go | 23 ++++--- .../devfile/cmd_devfile_push_test.go | 10 +-- .../devfile/debug/cmd_devfile_debug_test.go | 12 ++-- .../docker/cmd_docker_devfile_push_test.go | 2 +- .../docker/cmd_docker_devfile_url_test.go | 2 +- tests/integration/devfile/utils/utils.go | 18 ++--- 23 files changed, 211 insertions(+), 138 deletions(-) delete mode 100644 tests/examples/source/devfiles/nodejs/project/app/app.js create mode 100644 tests/examples/source/devfiles/nodejs/project/server.js create mode 100644 tests/examples/source/devfiles/nodejs/project/test/test.js diff --git a/docs/public/debugging-using-devfile.adoc b/docs/public/debugging-using-devfile.adoc index 3d74c665e04..fe4493bedf1 100644 --- a/docs/public/debugging-using-devfile.adoc +++ b/docs/public/debugging-using-devfile.adoc @@ -10,7 +10,7 @@ metadata: name: test-devfile projects: - - name: nodejs-web-app + name: nodejs-starter source: type: git location: "https://github.com/che-samples/web-nodejs-sample.git" @@ -32,19 +32,19 @@ commands: - type: exec component: runtime command: "npm install" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter/app - name: devrun actions: - type: exec component: runtime command: "nodemon app.js" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter/app - name: debugrun actions: - type: exec component: runtime command: "nodemon --inspect=${DEBUG_PORT}" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/ + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter/ ``` - Now we need to create the component using `odo create nodejs` diff --git a/pkg/odo/cli/component/create.go b/pkg/odo/cli/component/create.go index b3b7f8d3de9..00f78404b44 100644 --- a/pkg/odo/cli/component/create.go +++ b/pkg/odo/cli/component/create.go @@ -136,8 +136,8 @@ Note: When you use odo with experimental mode enabled and create devfile compone # Create new Node.js component with custom ports, additional environment variables and memory and cpu limits %[1]s nodejs --port 8080,8100/tcp,9100/udp --env key=value,key1=value1 --memory 4Gi --cpu 2 -# Create new Node.js component and download the sample project named nodejs-web-app -%[1]s nodejs --downloadSource=nodejs-web-app`) +# Create new Node.js component and download the sample project named nodejs-starter +%[1]s nodejs --downloadSource=nodejs-starter`) const defaultProjectName = "devfile-project-name" diff --git a/tests/examples/source/devfiles/nodejs/devfile-no-endpoints.yaml b/tests/examples/source/devfiles/nodejs/devfile-no-endpoints.yaml index df9f9ccf1f5..a3df3f19733 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-no-endpoints.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-no-endpoints.yaml @@ -2,29 +2,29 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi mountSources: true commands: - exec: id: devbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: devrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-debugrun.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-debugrun.yaml index 30f9a8ec150..d3454b05504 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-with-debugrun.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-with-debugrun.yaml @@ -2,13 +2,13 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi endpoints: - name: "3000/tcp" @@ -21,24 +21,24 @@ commands: - exec: id: devbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: devrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true - exec: id: debugrun component: runtime - commandLine: "nodemon --inspect=${DEBUG_PORT}" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/ + commandLine: npm run debug + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: debug isDefault: true \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-multiple-defaults.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-multiple-defaults.yaml index 08ee97cf76f..ca1f34f58c8 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-with-multiple-defaults.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-with-multiple-defaults.yaml @@ -2,13 +2,13 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi endpoints: - name: "3000/tcp" @@ -21,35 +21,35 @@ commands: - exec: id: firstbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: secondbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: thirdbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter - exec: id: firstrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run - exec: id: secondrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-restart.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-restart.yaml index a8f131fc1bb..b54c3522ead 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-with-restart.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-with-restart.yaml @@ -2,21 +2,21 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi mountSources: true commands: - exec: id: devbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true @@ -25,8 +25,8 @@ commands: attributes: restart: "false" component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-sparseCheckoutDir.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-sparseCheckoutDir.yaml index d7d3fc2f5f5..47bca5e78b2 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-with-sparseCheckoutDir.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-with-sparseCheckoutDir.yaml @@ -3,14 +3,14 @@ metadata: name: test-devfile projects: - - name: nodejs-web-app + name: nodejs-starter source: type: git location: "https://github.com/che-samples/web-nodejs-sample.git" sparseCheckoutDir: /app/ components: - type: dockerimage - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 endpoints: - name: "3000/tcp" port: 3000 @@ -25,23 +25,23 @@ commands: actions: - type: exec component: runtime - command: "npm install" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + command: npm install + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter - name: devbuild actions: - type: exec component: runtime - command: "npm install" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + command: npm install + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter - name: run actions: - type: exec component: runtime - command: "nodemon app.js" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + command: npm start + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter - name: devrun actions: - type: exec component: runtime - command: "nodemon app.js" - workdir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + command: npm start + workdir: ${CHE_PROJECTS_ROOT}/nodejs-starter diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-volumes.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-volumes.yaml index ede677dbbd2..d8d9dfb2abe 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-with-volumes.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-with-volumes.yaml @@ -2,7 +2,7 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: location: "https://github.com/che-samples/web-nodejs-sample.git" components: diff --git a/tests/examples/source/devfiles/nodejs/devfile-without-devbuild.yaml b/tests/examples/source/devfiles/nodejs/devfile-without-devbuild.yaml index 8f6cc410819..50d74ffc43a 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-without-devbuild.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-without-devbuild.yaml @@ -2,13 +2,13 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi env: - name: FOO @@ -24,8 +24,8 @@ commands: - exec: id: devrun component: runtime - commandLine: "npm install && nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: "npm install && npm start" + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile-without-devinit.yaml b/tests/examples/source/devfiles/nodejs/devfile-without-devinit.yaml index 9645b1e751c..ed2d3b24658 100644 --- a/tests/examples/source/devfiles/nodejs/devfile-without-devinit.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile-without-devinit.yaml @@ -2,9 +2,9 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime @@ -24,16 +24,16 @@ commands: - exec: id: devbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: devrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/devfile.yaml b/tests/examples/source/devfiles/nodejs/devfile.yaml index 70ed8920c2d..208e3a1655e 100644 --- a/tests/examples/source/devfiles/nodejs/devfile.yaml +++ b/tests/examples/source/devfiles/nodejs/devfile.yaml @@ -2,13 +2,13 @@ schemaVersion: 2.0.0 metadata: name: test-devfile projects: - - name: nodejs-web-app + - name: nodejs-starter git: - location: "https://github.com/che-samples/web-nodejs-sample.git" + location: "https://github.com/odo-devfiles/nodejs-ex.git" components: - container: name: runtime - image: quay.io/eclipse/che-nodejs10-ubi:nightly + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 memoryLimit: 1024Mi endpoints: - name: "3000/tcp" @@ -21,30 +21,30 @@ commands: - exec: id: devbuild component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build isDefault: true - exec: id: build component: runtime - commandLine: "npm install" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm install + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: build - exec: id: devrun component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run isDefault: true - exec: id: run component: runtime - commandLine: "nodemon app.js" - workingDir: ${CHE_PROJECTS_ROOT}/nodejs-web-app/app + commandLine: npm start + workingDir: ${CHE_PROJECTS_ROOT}/nodejs-starter group: kind: run \ No newline at end of file diff --git a/tests/examples/source/devfiles/nodejs/project/app/app.js b/tests/examples/source/devfiles/nodejs/project/app/app.js deleted file mode 100644 index 42ff4183f17..00000000000 --- a/tests/examples/source/devfiles/nodejs/project/app/app.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2012-2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ - -/*eslint-env node*/ - -var express = require('express'); -var app = express(); - -app.get('/', function (req, res) { - res.send('Hello World!'); -}); - -app.listen(3000, function () { - console.log('Example app listening on port 3000!'); -}); diff --git a/tests/examples/source/devfiles/nodejs/project/package.json b/tests/examples/source/devfiles/nodejs/project/package.json index 2c28053506f..c0a041fd3aa 100644 --- a/tests/examples/source/devfiles/nodejs/project/package.json +++ b/tests/examples/source/devfiles/nodejs/project/package.json @@ -1,14 +1,17 @@ { - "name": "nodejs-sample", + "name": "nodejs-starter", "version": "1.0.0", - "description": "", - "main": "app/app.js", + "description": "Simple Node.js application", + "license": "EPL-2.0", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node server.js", + "debug": "node --inspect-brk=${DEBUG_PORT} server.js", + "test": "node test/test.js" }, - "author": "", - "license": "EPL-2.0", "dependencies": { - "express": "^4.13.4" + "express": "^4.17.1", + "pino": "^6.2.1", + "pino-http": "^5.1.0", + "prom-client": "^12.0.0" } } diff --git a/tests/examples/source/devfiles/nodejs/project/server.js b/tests/examples/source/devfiles/nodejs/project/server.js new file mode 100644 index 00000000000..babec86f97c --- /dev/null +++ b/tests/examples/source/devfiles/nodejs/project/server.js @@ -0,0 +1,66 @@ +const Prometheus = require('prom-client') +const express = require('express'); +const http = require('http'); + +Prometheus.collectDefaultMetrics(); + +const requestHistogram = new Prometheus.Histogram({ + name: 'http_request_duration_seconds', + help: 'Duration of HTTP requests in seconds', + labelNames: ['code', 'handler', 'method'], + buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5] +}) + +const requestTimer = (req, res, next) => { + const path = new URL(req.url, `http://${req.hostname}`).pathname + const stop = requestHistogram.startTimer({ + method: req.method, + handler: path + }) + res.on('finish', () => { + stop({ + code: res.statusCode + }) + }) + next() +} + +const app = express(); +const server = http.createServer(app) + +// See: http://expressjs.com/en/4x/api.html#app.settings.table +const PRODUCTION = app.get('env') === 'production'; + +// Administrative routes are not timed or logged, but for non-admin routes, pino +// overhead is included in timing. +app.get('/ready', (req, res) => res.status(200).json({status:"ok"})); +app.get('/live', (req, res) => res.status(200).json({status:"ok"})); +app.get('/metrics', (req, res, next) => { + res.set('Content-Type', Prometheus.register.contentType) + res.end(Prometheus.register.metrics()) +}) + +// Time routes after here. +app.use(requestTimer); + +// Log routes after here. +const pino = require('pino')({ + level: PRODUCTION ? 'info' : 'debug', +}); +app.use(require('pino-http')({logger: pino})); + +app.get('/', (req, res) => { + // Use req.log (a `pino` instance) to log JSON: + req.log.info({message: 'Hello from Node.js Starter Application!'}); + res.send('Hello from Node.js Starter Application!'); +}); + +app.get('*', (req, res) => { + res.status(404).send("Not Found"); +}); + +// Listen and serve. +const PORT = process.env.PORT || 3000; +server.listen(PORT, () => { + console.log(`App started on PORT ${PORT}`); +}); diff --git a/tests/examples/source/devfiles/nodejs/project/test/test.js b/tests/examples/source/devfiles/nodejs/project/test/test.js new file mode 100644 index 00000000000..14a959f2698 --- /dev/null +++ b/tests/examples/source/devfiles/nodejs/project/test/test.js @@ -0,0 +1,21 @@ +var assert = require('assert'); + +(function(){ + 'use strict'; + + equal('should pass', function() { + assert(1 === 1); + }); + + function equal(desc, fn) { + try { + fn(); + console.log('\x1b[32m%s\x1b[0m', '\u2714 ' + desc); + console.log("Add your tests in this ./test directory"); + } catch (error) { + console.log('\n'); + console.log('\x1b[31m%s\x1b[0m', '\u2718 ' + desc); + console.error(error); + } + } + })(); \ No newline at end of file diff --git a/tests/integration/devfile/cmd_devfile_catalog_test.go b/tests/integration/devfile/cmd_devfile_catalog_test.go index c4fbb9a2903..842e82c9a1c 100644 --- a/tests/integration/devfile/cmd_devfile_catalog_test.go +++ b/tests/integration/devfile/cmd_devfile_catalog_test.go @@ -106,7 +106,7 @@ var _ = Describe("odo devfile catalog command tests", func() { output := helper.CmdShouldPass("odo", "registry", "list") helper.MatchAllInOutput(output, []string{registryName, addRegistryURL}) output = helper.CmdShouldPass("odo", "catalog", "describe", "component", "nodejs") - helper.MatchAllInOutput(output, []string{"name: nodejs-web-app", "Registry: DefaultDevfileRegistry", "Registry: " + registryName}) + helper.MatchAllInOutput(output, []string{"name: nodejs-starter", "Registry: DefaultDevfileRegistry", "Registry: " + registryName}) }) }) Context("When executing catalog describe component with a component name that does not have a devfile component", func() { diff --git a/tests/integration/devfile/cmd_devfile_create_test.go b/tests/integration/devfile/cmd_devfile_create_test.go index e451fbd789e..41f4440ad4d 100644 --- a/tests/integration/devfile/cmd_devfile_create_test.go +++ b/tests/integration/devfile/cmd_devfile_create_test.go @@ -230,7 +230,7 @@ var _ = Describe("odo devfile create command tests", func() { It("should successfully create the component specified and download the source", func() { contextDevfile := helper.CreateNewContext() helper.Chdir(contextDevfile) - helper.CmdShouldPass("odo", "create", "nodejs", "--downloadSource=nodejs-web-app") + helper.CmdShouldPass("odo", "create", "nodejs", "--downloadSource=nodejs-starter") expectedFiles := []string{"package.json", "package-lock.json", "README.md", devfile} Expect(helper.VerifyFilesExist(contextDevfile, expectedFiles)).To(Equal(true)) helper.DeleteDir(contextDevfile) diff --git a/tests/integration/devfile/cmd_devfile_debug_test.go b/tests/integration/devfile/cmd_devfile_debug_test.go index 341542f9ac0..7bc78341c63 100644 --- a/tests/integration/devfile/cmd_devfile_debug_test.go +++ b/tests/integration/devfile/cmd_devfile_debug_test.go @@ -1,7 +1,6 @@ package devfile import ( - "github.com/openshift/odo/pkg/util" "os" "path/filepath" "runtime" @@ -9,6 +8,8 @@ import ( "strings" "time" + "github.com/openshift/odo/pkg/util" + "github.com/openshift/odo/tests/helper" . "github.com/onsi/ginkgo" @@ -53,11 +54,12 @@ 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.CmdShouldPass("git", "clone", "https://github.com/che-samples/web-nodejs-sample.git", projectDirPath) + helper.MakeDir(projectDirPath) helper.Chdir(projectDirPath) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, componentName) - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), projectDirPath) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(projectDirPath, "devfile-with-debugrun.yaml")) helper.RenameFile("devfile-with-debugrun.yaml", "devfile.yaml") helper.CmdShouldPass("odo", "push", "--debug") @@ -84,11 +86,12 @@ 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.CmdShouldPass("git", "clone", "https://github.com/che-samples/web-nodejs-sample.git", projectDirPath) + helper.MakeDir(projectDirPath) helper.Chdir(projectDirPath) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, componentName) - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), projectDirPath) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(projectDirPath, "devfile-with-debugrun.yaml")) helper.RenameFile("devfile-with-debugrun.yaml", "devfile.yaml") helper.CmdShouldPass("odo", "push") helper.CmdShouldPass("odo", "push", "--debug") @@ -108,11 +111,12 @@ 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.CmdShouldPass("git", "clone", "https://github.com/che-samples/web-nodejs-sample.git", projectDirPath) + helper.MakeDir(projectDirPath) helper.Chdir(projectDirPath) helper.CmdShouldPass("odo", "create", "nodejs", "nodejs-cmp-"+namespace, "--project", namespace) - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), projectDirPath) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(projectDirPath, "devfile-with-debugrun.yaml")) helper.RenameFile("devfile-with-debugrun.yaml", "devfile.yaml") helper.CmdShouldPass("odo", "push", "--debug") @@ -135,11 +139,12 @@ 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.CmdShouldPass("git", "clone", "https://github.com/che-samples/web-nodejs-sample.git", projectDirPath) + helper.MakeDir(projectDirPath) helper.Chdir(projectDirPath) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, componentName) - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), projectDirPath) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(projectDirPath, "devfile-with-debugrun.yaml")) helper.RenameFile("devfile-with-debugrun.yaml", "devfile.yaml") helper.CmdShouldPass("odo", "push", "--debug") diff --git a/tests/integration/devfile/cmd_devfile_push_test.go b/tests/integration/devfile/cmd_devfile_push_test.go index a4fd3432366..16e5abca1c2 100644 --- a/tests/integration/devfile/cmd_devfile_push_test.go +++ b/tests/integration/devfile/cmd_devfile_push_test.go @@ -15,7 +15,7 @@ import ( var _ = Describe("odo devfile push command tests", func() { var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string - var sourcePath = "/projects/nodejs-web-app" + var sourcePath = "/projects/nodejs-starter" // Using program commmand according to cliRunner in devfile cliRunner := helper.GetCliRunner() @@ -153,28 +153,28 @@ var _ = Describe("odo devfile push command tests", func() { podName, "", namespace, - []string{"stat", "/projects/nodejs-web-app/app/app.js"}, + []string{"stat", "/projects/nodejs-starter/server.js"}, func(cmdOp string, err error) bool { statErr = err return true }, ) Expect(statErr).ToNot(HaveOccurred()) - Expect(os.Remove(filepath.Join(context, "app", "app.js"))).NotTo(HaveOccurred()) + Expect(os.Remove(filepath.Join(context, "server.js"))).NotTo(HaveOccurred()) helper.CmdShouldPass("odo", "push", "--project", namespace) cliRunner.CheckCmdOpInRemoteDevfilePod( podName, "", namespace, - []string{"stat", "/projects/nodejs-web-app/app/app.js"}, + []string{"stat", "/projects/nodejs-starter/server.js"}, func(cmdOp string, err error) bool { statErr = err return true }, ) Expect(statErr).To(HaveOccurred()) - Expect(statErr.Error()).To(ContainSubstring("cannot stat '/projects/nodejs-web-app/app/app.js': No such file or directory")) + Expect(statErr.Error()).To(ContainSubstring("cannot stat '/projects/nodejs-starter/server.js': No such file or directory")) }) It("should build when no changes are detected in the directory and force flag is enabled", func() { diff --git a/tests/integration/devfile/debug/cmd_devfile_debug_test.go b/tests/integration/devfile/debug/cmd_devfile_debug_test.go index 58776a2a949..9555334df5c 100644 --- a/tests/integration/devfile/debug/cmd_devfile_debug_test.go +++ b/tests/integration/devfile/debug/cmd_devfile_debug_test.go @@ -1,15 +1,16 @@ package debug import ( - "github.com/openshift/odo/pkg/envinfo" - "github.com/openshift/odo/pkg/testingutil" - "github.com/openshift/odo/tests/helper" "os" "path/filepath" "strconv" "strings" "time" + "github.com/openshift/odo/pkg/envinfo" + "github.com/openshift/odo/pkg/testingutil" + "github.com/openshift/odo/tests/helper" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -64,11 +65,12 @@ var _ = Describe("odo devfile debug command serial tests", func() { // Devfile push requires experimental mode to be set helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true", "-f") - helper.CmdShouldPass("git", "clone", "https://github.com/che-samples/web-nodejs-sample.git", projectDirPath) + helper.MakeDir(projectDirPath) helper.Chdir(projectDirPath) helper.CmdShouldPass("odo", "create", "nodejs", "--project", namespace, componentName) - helper.CopyExample(filepath.Join("source", "devfiles", "nodejs"), projectDirPath) + helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), projectDirPath) + helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-debugrun.yaml"), filepath.Join(projectDirPath, "devfile-with-debugrun.yaml")) helper.RenameFile("devfile-with-debugrun.yaml", "devfile.yaml") helper.CmdShouldPass("odo", "push", "--debug") diff --git a/tests/integration/devfile/docker/cmd_docker_devfile_push_test.go b/tests/integration/devfile/docker/cmd_docker_devfile_push_test.go index a5c1b62f880..0f3d978792f 100644 --- a/tests/integration/devfile/docker/cmd_docker_devfile_push_test.go +++ b/tests/integration/devfile/docker/cmd_docker_devfile_push_test.go @@ -14,7 +14,7 @@ import ( var _ = Describe("odo docker devfile push command tests", func() { var context, currentWorkingDirectory, cmpName string - var sourcePath = "/projects/nodejs-web-app" + var sourcePath = "/projects/nodejs-starter" dockerClient := helper.NewDockerRunner("docker") diff --git a/tests/integration/devfile/docker/cmd_docker_devfile_url_test.go b/tests/integration/devfile/docker/cmd_docker_devfile_url_test.go index 5088d07d0b9..8098320066c 100644 --- a/tests/integration/devfile/docker/cmd_docker_devfile_url_test.go +++ b/tests/integration/devfile/docker/cmd_docker_devfile_url_test.go @@ -99,7 +99,7 @@ var _ = Describe("odo docker devfile url command tests", func() { url := strings.TrimSpace(helper.ExtractSubString(output, "127.0.0.1", "created")) - helper.HttpWaitFor("http://"+url, "Hello World!", 30, 1) + helper.HttpWaitFor("http://"+url, "Hello from Node.js Starter Application!", 30, 1) }) }) diff --git a/tests/integration/devfile/utils/utils.go b/tests/integration/devfile/utils/utils.go index 6236c334b0d..30a18e9adfd 100644 --- a/tests/integration/devfile/utils/utils.go +++ b/tests/integration/devfile/utils/utils.go @@ -52,7 +52,7 @@ func ExecWithMissingBuildCommand(projectDirPath, cmpName, namespace string) { args = useProjectIfAvailable(args, namespace) output := helper.CmdShouldPass("odo", args...) Expect(output).NotTo(ContainSubstring("Executing devbuild command")) - Expect(output).To(ContainSubstring("Executing devrun command \"npm install && nodemon app.js\"")) + Expect(output).To(ContainSubstring("Executing devrun command \"npm install && npm start\"")) } // ExecWithMissingRunCommand executes odo push with a missing run command @@ -88,7 +88,7 @@ func ExecWithCustomCommand(projectDirPath, cmpName, namespace string) { output := helper.CmdShouldPass("odo", args...) helper.MatchAllInOutput(output, []string{ "Executing build command \"npm install\"", - "Executing run command \"nodemon app.js\"", + "Executing run command \"npm start\"", }) } @@ -142,7 +142,7 @@ func ExecMultipleDefaultsWithFlags(projectDirPath, cmpName, namespace string) { output := helper.CmdShouldPass("odo", args...) helper.MatchAllInOutput(output, []string{ "Executing firstbuild command \"npm install\"", - "Executing secondrun command \"nodemon app.js\"", + "Executing secondrun command \"npm start\"", }) } @@ -160,7 +160,7 @@ func ExecCommandWithoutGroupUsingFlags(projectDirPath, cmpName, namespace string output := helper.CmdShouldPass("odo", args...) helper.MatchAllInOutput(output, []string{ "Executing thirdbuild command \"npm install\"", - "Executing secondrun command \"nodemon app.js\"", + "Executing secondrun command \"npm start\"", }) } @@ -198,7 +198,7 @@ func ExecPushToTestFileChanges(projectDirPath, cmpName, namespace string) { output := helper.CmdShouldPass("odo", args...) Expect(output).To(ContainSubstring("No file changes detected, skipping build")) - helper.ReplaceString(filepath.Join(projectDirPath, "app", "app.js"), "Hello World!", "UPDATED!") + helper.ReplaceString(filepath.Join(projectDirPath, "server.js"), "Hello from Node.js", "UPDATED!") output = helper.CmdShouldPass("odo", args...) Expect(output).To(ContainSubstring("Syncing files to the component")) } @@ -258,7 +258,7 @@ func ExecWithRestartAttribute(projectDirPath, cmpName, namespace string) { args = []string{"push"} args = useProjectIfAvailable(args, namespace) output := helper.CmdShouldPass("odo", args...) - Expect(output).To(ContainSubstring("Executing devrun command \"nodemon app.js\"")) + Expect(output).To(ContainSubstring("Executing devrun command \"npm start\"")) args = []string{"push", "-f"} args = useProjectIfAvailable(args, namespace) @@ -306,7 +306,7 @@ func OdoWatch(odoV1Watch OdoV1Watch, odoV2Watch OdoV2Watch, project, context, fl helper.DeleteDir(filepath.Join(context, "abcd")) if isDevfileTest { - helper.ReplaceString(filepath.Join(context, "app", "app.js"), "Hello", "Hello odo") + helper.ReplaceString(filepath.Join(context, "server.js"), "Hello", "Hello odo") } else { if odoV1Watch.SrcType == "openjdk" { helper.ReplaceString(filepath.Join(context, "src", "main", "java", "MessageProducer.java"), "Hello", "Hello odo") @@ -377,7 +377,7 @@ func validateContainerExecListDir(odoV1Watch OdoV1Watch, odoV2Watch OdoV2Watch, if isDevfileTest { cliRunner := runner.(helper.CliRunner) podName := cliRunner.GetRunningPodNameByComponent(odoV2Watch.CmpName, project) - stdOut = cliRunner.ExecListDir(podName, project, "/projects/nodejs-web-app") + stdOut = cliRunner.ExecListDir(podName, project, "/projects/nodejs-starter") } else { ocRunner := runner.(helper.OcRunner) podName := ocRunner.GetRunningPodNameOfComp(odoV1Watch.SrcType+"-app", project) @@ -389,7 +389,7 @@ func validateContainerExecListDir(odoV1Watch OdoV1Watch, odoV2Watch OdoV2Watch, dockerRunner := runner.(helper.DockerRunner) containers := dockerRunner.GetRunningContainersByCompAlias(odoV2Watch.CmpName, "runtime") Expect(len(containers)).To(Equal(1)) - stdOut = dockerRunner.ExecContainer(containers[0], "ls -la /projects/nodejs-web-app") + stdOut = dockerRunner.ExecContainer(containers[0], "ls -la /projects/nodejs-starter") default: return fmt.Errorf("Platform %s is not supported", platform) }