From c920648404c515f4512e4f2cbb27612295f8ed5b Mon Sep 17 00:00:00 2001 From: vamsee Date: Wed, 11 Sep 2019 16:34:26 +0530 Subject: [PATCH 1/8] Using NPM_REGISTRY and CI_JOB_ID --- .gitlab-ci.yml | 16 +++++++--------- package.json | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9bf575d..7988858 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,7 +20,7 @@ npminstall: - status_eslint=0 - exit_status=0 - npm set progress=false - - npm config set registry http://10.188.25.62:9002/ + - npm config set registry ${NPM_REGISTRY} - time npm install eslint babel-eslint --no-optional - if npm run lint; then status_eslint=0; else status_eslint=1; fi - if [ $status_eslint == 1 ]; then exit_status=1 && echo "esLint errors exist"; fi @@ -29,7 +29,6 @@ npminstall: - time npm install --no-optional - echo "Node Modules Installed" artifacts: - untracked: true expire_in: 2h paths: - node_modules/ @@ -44,12 +43,11 @@ mongotest: - export NODE_ENV=mongo - export MONGO_HOST="10.73.53.144" - export DB=mongo - - export DB_NAME=${CI_PIPELINE_ID}_mongo - - npm config set registry http://10.188.25.62:9002/ + - export DB_NAME=${CI_JOB_ID}_mongo + - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover artifacts: - untracked: true expire_in: 2h paths: - coverage/ @@ -64,9 +62,9 @@ postgrestest: - export NODE_ENV=postgres - export DB=postgres - export POSTGRES_HOST="10.73.53.144" - - export DB_NAME=${CI_PIPELINE_ID}_pg + - export DB_NAME=${CI_JOB_ID}_pg - export ENABLE_DS_AUTOUPDATE=true - - npm config set registry http://10.188.25.62:9002/ + - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover tags: @@ -83,8 +81,8 @@ oracletest: - export ORACLE_SYSUSER=oeadmin - export ORACLE_SYSPASSWORD=oeadmin - export ORACLE_SID=ORCLCDB - - export DB_NAME=${CI_PIPELINE_ID}_pg - - npm config set registry http://10.188.25.62:9002/ + - export DB_NAME=${CI_JOB_ID}_pg + - npm config set registry ${NPM_REGISTRY} - time npm install git+http://evgit/atul/oe-connector-oracle.git --no-optional - time npm install --no-optional - mv /oracledb node_modules/ diff --git a/package.json b/package.json index 454b186..5b02cc0 100755 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "camelcase": "5.0.0", "lodash": "4.17.14", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#2.1.0" + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master" }, "devDependencies": { "babel-eslint": "7.2.3", @@ -39,7 +39,7 @@ "superagent-defaults": "0.1.14", "supertest": "3.4.2", "loopback-connector-mongodb": "3.9.2", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#2.0.0" + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" }, "repository": { "type": "git", From 270d7490dca2ce990372e542e0822cdba1b3a1c8 Mon Sep 17 00:00:00 2001 From: vamsee Date: Wed, 11 Sep 2019 17:17:50 +0530 Subject: [PATCH 2/8] Using CEP_RUNNER --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7988858..65160ef 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,7 +33,7 @@ npminstall: paths: - node_modules/ tags: - - ubuntu-runner + - CEP_RUNNER mongotest: @@ -53,7 +53,7 @@ mongotest: - coverage/ when: on_failure tags: - - ubuntu-runner + - CEP_RUNNER postgrestest: stage: pre-build-test From 3916ab34bbd8e022dffba55fe5d9f70c92973a77 Mon Sep 17 00:00:00 2001 From: vamsee Date: Mon, 23 Sep 2019 11:21:10 +0530 Subject: [PATCH 3/8] Using node 10.16.0 in CI --- .gitlab-ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65160ef..c4439c2 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,15 +3,19 @@ stages: - pre-build-test - cleanup -image: $REGISTRY/debian-node-oracle-docker variables: + DOMAIN_NAME: oecloud.local + PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} + EXECUTOR_IMAGE: oecloud-executor:10.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + +image: ${REGISTRY}/${EXECUTOR_IMAGE} before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} - - export pipelineId=${CI_PIPELINE_ID//[^[:alnum:]]/} npminstall: stage: pre-build @@ -72,6 +76,7 @@ postgrestest: oracletest: + image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test script: - echo 'Performing Oracle Test' From 7f695e95ebaa3d7e37cf75370fb788f0a4a99fcd Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:05:27 +0530 Subject: [PATCH 4/8] Using node 12.13.0 in CI --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c4439c2..34a68ab 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,8 +7,8 @@ variables: DOMAIN_NAME: oecloud.local PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} - EXECUTOR_IMAGE: oecloud-executor:10.x - EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + EXECUTOR_IMAGE: oecloud-executor:12.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:12.x image: ${REGISTRY}/${EXECUTOR_IMAGE} From d19f9e24d578eb3ed6f9084435bb40068dc0452c Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:46:25 +0530 Subject: [PATCH 5/8] Removing user and password from mongo db config --- test/datasources.mongo.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index 05f3930..bb5e995 100755 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -17,15 +17,13 @@ module.exports = "connector": "transient" }, "db": { - "host": mongoHost, - "port": 27017, - "url": "mongodb://" + mongoHost + ":27017/" + dbName, - "database": dbName, - "password": "admin", - "name": "db", - "connector": "mongodb", - "user": "admin", - "connectionTimeout": 500000 + 'host': mongoHost, + 'port': 27017, + 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'database': dbName, + 'name': 'db', + 'connector': 'mongodb', + 'connectionTimeout': 500000 } }; From eb0383f49e5ce2f96c3409fcf0545b49ac9c4826 Mon Sep 17 00:00:00 2001 From: atul Date: Fri, 13 Dec 2019 01:58:25 -0800 Subject: [PATCH 6/8] moving oe-cloud as dev dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5b02cc0..dfc754d 100755 --- a/package.json +++ b/package.json @@ -15,8 +15,7 @@ }, "dependencies": { "camelcase": "5.0.0", - "lodash": "4.17.14", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master" + "lodash": "4.17.14" }, "devDependencies": { "babel-eslint": "7.2.3", @@ -39,6 +38,7 @@ "superagent-defaults": "0.1.14", "supertest": "3.4.2", "loopback-connector-mongodb": "3.9.2", + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" }, "repository": { From 41c9868822532f990fe61fd279b232a72e0b00b5 Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 10 Jan 2020 16:52:22 +0530 Subject: [PATCH 7/8] removed unneeded packages and updated ci --- .eslintignore | 13 +-- .eslintrc | 2 +- .gitignore | 3 +- .gitlab-ci.yml | 145 +++++++++++++++++++++-------- Gruntfile.js | 38 +------- package.json | 15 +-- test/boot/populate-data.js | 12 +-- test/datasources.json | 5 +- test/datasources.mongo.js | 24 ++--- test/datasources.oracle.js | 10 +- test/datasources.postgres.js | 39 ++++---- test/oracle-utility.js | 176 +++++++++++++++++++---------------- test/server.js | 6 +- test/test.js | 104 ++++++++++----------- 14 files changed, 311 insertions(+), 281 deletions(-) diff --git a/.eslintignore b/.eslintignore index 398a1eb..9c8d714 100755 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ -/client/ -/coverage/ -/node_modules/ -server/dropdb.js -/lib/expression-language/expression-syntax-parser.js -/test/ +build/ +client/ +coverage/ +node_modules/ +test/ +drop.js +Gruntfile.js diff --git a/.eslintrc b/.eslintrc index 8f2f7cc..6edc78f 100755 --- a/.eslintrc +++ b/.eslintrc @@ -111,7 +111,7 @@ "no-undefined": 1, // http://eslint.org/docs/rules/no-undefined "no-with": 2, // http://eslint.org/docs/rules/no-with "handle-callback-err": 1, // http://eslint.org/docs/rules/handle-callback-err - "radix": 2, // http://eslint.org/docs/rules/radix + "radix": 0, // http://eslint.org/docs/rules/radix "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife "yoda": 2, // http://eslint.org/docs/rules/yoda diff --git a/.gitignore b/.gitignore index 0121bea..4631a8a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ out/ *.heapsnapshot *.zip /common/models/test -package-lock.json \ No newline at end of file +package-lock.json +oracle-user.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 34a68ab..27c3940 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,8 @@ stages: - pre-build - pre-build-test - - cleanup + - push-artifacts + - performance variables: DOMAIN_NAME: oecloud.local @@ -16,97 +17,161 @@ before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} + - if [ ${group} == "oecloudio" ]; then export APP_IMAGE_NAME=$project; else export APP_IMAGE_NAME=$group"-"$project; fi + - export APP_IMAGE_NAME=$(echo $APP_IMAGE_NAME | tr '[:upper:]' '[:lower:]') + - if [ ${branch} == "master" ]; then export APP_TAG=latest; else export APP_TAG=${branch}; fi + - export APP_TAG=$(echo $APP_TAG | tr '[:upper:]' '[:lower:]') + + - npm config set unsafe-perm true + - npm config set progress false + - npm config set registry ${NPM_REGISTRY} + # - npm config set registry https://registry.npmjs.org/ npminstall: stage: pre-build script: - echo "Performing code style check..." - - status_eslint=0 - - exit_status=0 - - npm set progress=false - - npm config set registry ${NPM_REGISTRY} + - export status_eslint=0 + - export exit_status=0 - time npm install eslint babel-eslint --no-optional - if npm run lint; then status_eslint=0; else status_eslint=1; fi - - if [ $status_eslint == 1 ]; then exit_status=1 && echo "esLint errors exist"; fi + - if [ $status_eslint == 1 ]; then export exit_status=1 && echo "esLint errors exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi - echo "Code style check done successfully" - time npm install --no-optional - echo "Node Modules Installed" + - npm config rm registry + - npm audit --json > vulnerabilities.json || true + - if npm audit; then status_vulnerabilities=0; else status_vulnerabilities=1; fi + - if [ $status_vulnerabilities == 1 ]; then echo "Dependency vulnerabilities exist"; fi + - if [ $exit_status == 1 ]; then exit $exit_status; fi artifacts: expire_in: 2h paths: - node_modules/ + - vulnerabilities.json tags: - CEP_RUNNER - mongotest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: mongo + DB: mongo + MONGO_HOST: 10.73.53.144 + MONGO_PORT: '27017' + DB_NAME: ${CI_JOB_ID}_mongo script: - echo 'Performing MongoDB Test' - - export NODE_ENV=mongo - - export MONGO_HOST="10.73.53.144" - - export DB=mongo - - export DB_NAME=${CI_JOB_ID}_mongo - - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover artifacts: expire_in: 2h paths: - coverage/ - when: on_failure tags: - CEP_RUNNER postgrestest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: postgres + DB: postgres + POSTGRES_HOST: 10.73.53.144 + POSTGRES_PORT: '5432' + DB_NAME: ${CI_JOB_ID}_pg + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing PostgreSQL Test' - - export NODE_ENV=postgres - - export DB=postgres - - export POSTGRES_HOST="10.73.53.144" - - export DB_NAME=${CI_JOB_ID}_pg - - export ENABLE_DS_AUTOUPDATE=true - - npm config set registry ${NPM_REGISTRY} - time npm install --no-optional - npm run grunt-cover tags: - - CEP_RUNNER - + - CEP_RUNNER oracletest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test + variables: + NODE_ENV: oracle + DB: oracle + ORACLE_HOST: 10.73.53.144 + ORACLE_PORT: '1521' + ORACLE_SYSUSER: oeadmin + ORACLE_SYSPASSWORD: oeadmin + ORACLE_SID: ORCLCDB + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing Oracle Test' - - export APP_TAG=oracle - - export NODE_ENV=oracle - - export ORACLE_HOST=10.73.53.144 - - export ORACLE_SYSUSER=oeadmin - - export ORACLE_SYSPASSWORD=oeadmin - - export ORACLE_SID=ORCLCDB - - export DB_NAME=${CI_JOB_ID}_pg - - npm config set registry ${NPM_REGISTRY} - - time npm install git+http://evgit/atul/oe-connector-oracle.git --no-optional + # - export DB_NAME=${CI_JOB_ID}_pg + # - time npm install git+http://evgit/oecloud.io/oe-connector-oracle.git#master --no-optional - time npm install --no-optional - mv /oracledb node_modules/ - - export CI_PROJECT_NAMESPACE=${group} - node test/oracle-utility.js - - export ORACLE_USERNAME=${CI_PROJECT_NAMESPACE}"-"${CI_PROJECT_NAME} - - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') - - export ORACLE_PASSWORD=$(echo $CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]') - - export ENABLE_DS_AUTOUPDATE=true + # - export ORACLE_USERNAME=${group}"_"${project} + # - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') + # - export ORACLE_PASSWORD=$(echo $group | tr '[:upper:]' '[:lower:]') + - . ./oracle-user.sh + - env | grep -i oracle - echo "Oracle user details:"${ORACLE_USERNAME}"/"${ORACLE_PASSWORD} - npm run grunt-cover tags: - - CEP_RUNNER - + - CEP_RUNNER -lastcleanup: - stage: cleanup +pushartifacts: + stage: push-artifacts script: - - echo "Finishing CI CD" + - echo "Copying all artifacts" + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp vulnerabilities.json ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp -r coverage/ ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - git clone http://10.73.97.24/oecloud.io/build-tools.git + - sh ./build-tools/push_artifacts.sh tags: - CEP_RUNNER + only: + - /^.*/@oecloud.io/oe-skeleton +.performancejob: + image: $REGISTRY/jmeter:docker + stage: performance + variables: + NODE_ENV: "mongo" + MONGO_HOST: "10.73.97.17" + MONGO_PORT: "27017" + DB_NAME: "${CI_JOB_ID}_mongo" + APP_PROTOCOL: "https" + APP_PORT: "443" + PERF_USERS: "1" + PERF_LOOPCOUNT: "50000" + script: + - export STACK_NAME=${APP_IMAGE_NAME}-${APP_TAG} + - export APP_URL=${APP_IMAGE_NAME}-${APP_TAG}.${PERF_DOMAIN_NAME} + - if [ ${branch} == "master" ]; then export STACK_NAME=${APP_IMAGE_NAME}; export APP_URL=${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}; fi + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + - time npm install --no-optional + - git clone http://10.73.97.24/oecloud.io/build-tools.git + - sed 's/\$REGISTRY/'"$REGISTRY"'/g' ./build-tools/performance/Dockerfile > Dockerfile + - echo "Building ${APP_IMAGE_NAME}:${APP_TAG} image and pushing to registry..." + - time docker image build -t ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} --no-cache --pull . + - time docker image push ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} + - echo "Image (${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG}) built and pushed to registry" + - docker stack deploy --compose-file ./build-tools/performance/docker-compose.yml ${STACK_NAME} + - export HTTP_RESPONSE_CODE=200 + - export countElapsed=0 + - export app_exit_status=0 + - export no_proxy=$no_proxy,${APP_URL} + - export NO_PROXY=$no_proxy + - echo "${DOCKER_ROUTER_HOST} ${APP_URL}" >> /etc/hosts + - export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions) + - while [ ${isStarted} -ne ${HTTP_RESPONSE_CODE} ]; do let countElapsed=countElapsed+1; echo ""; sleep 10; export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions); echo -n "Waiting till the URL is up..."; echo ${isStarted}; if [ $countElapsed -eq 18 ] ; then export app_exit_status=1; export isStarted=${HTTP_RESPONSE_CODE}; fi; done + - if [ $app_exit_status -eq 1 ]; then echo "App failed to start....."; docker stack ps ${STACK_NAME}; docker service logs ${STACK_NAME}_web; docker stack rm ${STACK_NAME}; exit $app_exit_status; else echo "Your application URL is accessible @ https://${APP_URL}/"; fi + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/performance + - sh ./build-tools/performance/performance.sh + - sh ./build-tools/push_artifacts.sh + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + when: manual + tags: + - PERF_RUNNER diff --git a/Gruntfile.js b/Gruntfile.js index bab7f14..94c3cdd 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,38 +10,6 @@ module.exports = function GruntConfig(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - mkdir: { - all: { - options: { - create: ['dist'] - } - } - }, - - copy: { - main: { - files: [ - // includes files within path and its sub-directories - { - expand: true, - src: ['**', '!node_modules/**', '!coverage/**'], - dest: 'dist/' - } - ] - } - }, - - mochaTest: { - test: { - options: { - quiet: false, - clearRequireCache: true, - timeout: 100000 - }, - src: ['test/test.js'] - } - }, - clean: { coverage: { src: ['coverage/'] @@ -72,12 +40,8 @@ module.exports = function GruntConfig(grunt) { }); // Add the grunt-mocha-test tasks. - grunt.loadNpmTasks('grunt-mocha-test'); - grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-contrib-clean'); - - grunt.loadNpmTasks('grunt-mkdir'); - grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.registerTask('test-with-coverage', ['clean:coverage', 'mocha_istanbul']); }; diff --git a/package.json b/package.json index dfc754d..81cec90 100755 --- a/package.json +++ b/package.json @@ -20,26 +20,21 @@ "devDependencies": { "babel-eslint": "7.2.3", "chai": "3.4.1", - "chai-datetime": "1.4.0", "chai-things": "0.2.0", "chalk": "1.1.1", "eslint": "4.10.0", "grunt": "1.0.4", - "grunt-banner": "0.6.0", "grunt-cli": "1.3.2", "grunt-contrib-clean": "2.0.0", - "grunt-contrib-copy": "1.0.0", - "grunt-jsbeautifier": "0.2.13", - "grunt-mkdir": "1.0.0", "grunt-mocha-istanbul": "5.0.2", - "grunt-mocha-test": "0.13.3", "istanbul": "0.4.5", "mocha": "5.2.0", - "superagent-defaults": "0.1.14", - "supertest": "3.4.2", - "loopback-connector-mongodb": "3.9.2", "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", + "superagent-defaults": "0.1.14", + "supertest": "3.4.2" }, "repository": { "type": "git", diff --git a/test/boot/populate-data.js b/test/boot/populate-data.js index 906849c..c1136d9 100755 --- a/test/boot/populate-data.js +++ b/test/boot/populate-data.js @@ -2,7 +2,7 @@ var loopback = require('loopback'); module.exports = function (app, done) { var Customer = loopback.findModel('Customer'); - Customer.destroyAll({}, { ignoreAutoScope : true }, function (err) { + Customer.destroyAll({}, { ignoreAutoScope: true }, function (err) { console.log(err); var item1 = { 'name': 'Customer A', @@ -24,15 +24,15 @@ module.exports = function (app, done) { 'name': 'BPO Customer A', 'age': 30 }; - Customer.create(item1, { ctx: { tenantId: "/default" } }, function (err, r) { - Customer.create(item2, { ctx: { tenantId: "/default/infosys" } }, function (err, r) { - Customer.create(item3, { ctx: { tenantId: "/default/infosys/ev" } }, function (err, r) { - Customer.create([item4, item5], { ctx: { tenantId: "/default/infosys/bpo" } }, function (err, r) { + Customer.create(item1, { ctx: { tenantId: '/default' } }, function (err, r) { + Customer.create(item2, { ctx: { tenantId: '/default/infosys' } }, function (err, r) { + Customer.create(item3, { ctx: { tenantId: '/default/infosys/ev' } }, function (err, r) { + Customer.create([item4, item5], { ctx: { tenantId: '/default/infosys/bpo' } }, function (err, r) { return done(); }); }); }); }); }); -} +}; diff --git a/test/datasources.json b/test/datasources.json index 7c07998..d0def1f 100755 --- a/test/datasources.json +++ b/test/datasources.json @@ -7,7 +7,6 @@ "name": "transient", "connector": "transient" }, - "db": { "host": "localhost", "port": 27017, @@ -15,10 +14,10 @@ "database": "oe-skeleton", "password": "admin", "name": "db", - "connector": "mongodb", + "connector": "oe-connector-mongodb", "user": "admin", "connectionTimeout": 500000, "connectTimeoutMS": 500000, "socketTimeoutMS": 500000 } -} +} \ No newline at end of file diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index bb5e995..70d8a86 100755 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -5,24 +5,24 @@ * */ var mongoHost = process.env.MONGO_HOST || 'localhost'; +var mongoPort = process.env.MONGO_PORT ? parseInt(process.env.MONGO_PORT) : 27017; var dbName = process.env.DB_NAME || 'oe-skeleton-test'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - "db": { + 'db': { 'host': mongoHost, - 'port': 27017, - 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'port': mongoPort, + 'url': 'mongodb://' + mongoHost + ':' + mongoPort + '/' + dbName, 'database': dbName, 'name': 'db', - 'connector': 'mongodb', + 'connector': 'oe-connector-mongodb', 'connectionTimeout': 500000 } }; diff --git a/test/datasources.oracle.js b/test/datasources.oracle.js index 8792ffd..a5db290 100755 --- a/test/datasources.oracle.js +++ b/test/datasources.oracle.js @@ -4,16 +4,10 @@ * Bangalore, India. All Rights Reserved. * */ -/** - ** - ** ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), - ** Bangalore, India. All Rights Reserved. - ** - **/ -var oracleSID = process.env.ORACLE_SID || 'orclpdb.ad.infosys.com'; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; var oracleUserName = process.env.ORACLE_USERNAME || 'oeadmin'; var oracleUserPassword = process.env.ORACLE_PASSWORD || 'oeadmin'; diff --git a/test/datasources.postgres.js b/test/datasources.postgres.js index 2ccfbb8..7ebb845 100755 --- a/test/datasources.postgres.js +++ b/test/datasources.postgres.js @@ -5,29 +5,28 @@ * */ var postgresHost = process.env.POSTGRES_HOST || 'localhost'; +var postgresPort = process.env.POSTGRES_PORT ? parseInt(process.env.POSTGRES_PORT) : 5432; var dbName = process.env.DB_NAME || 'oe-skeleton-test'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - - "db": { - "host": postgresHost, - "port": 5432, - "url": "postgres://postgres:postgres@" + postgresHost + ":5432/" + dbName, - "database": dbName, - "password": "postgres", - "name": "db", - "connector": "oe-connector-postgresql", - "user": "postgres", - "max": 50, - "connectionTimeout": 50000 + 'db': { + 'host': postgresHost, + 'port': postgresPort, + 'url': 'postgres://postgres:postgres@' + postgresHost + ':' + postgresPort + '/' + dbName, + 'database': dbName, + 'password': 'postgres', + 'name': 'db', + 'connector': 'oe-connector-postgresql', + 'user': 'postgres', + 'max': 50, + 'connectionTimeout': 50000 } }; diff --git a/test/oracle-utility.js b/test/oracle-utility.js index 153da7f..40a1734 100755 --- a/test/oracle-utility.js +++ b/test/oracle-utility.js @@ -15,22 +15,29 @@ // ORACLE_SYSUSER // ORACLE_SYSPASSWORD // ORACLE_SID -// CI_PROJECT_NAME // CI_PROJECT_NAMESPACE +// CI_PROJECT_NAME var oracledb = require('oracledb'); var async = require('async'); +var fs = require('fs'); +var os = require('os'); + var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleConnectSettings = { 'password': process.env.ORACLE_SYSPASSWORD || 'manager1', 'user': process.env.ORACLE_SYSUSER || 'sys', - 'connectString': oracleHost + ':' + oraclePort + '/' + (process.env.ORACLE_SID || 'orclpdb.ad.infosys.com') + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID }; -var userName = process.env.CI_PROJECT_NAMESPACE.toUpperCase() + '-' + (process.env.CI_PROJECT_NAME || 'oecloud').toUpperCase(); -var password = process.env.CI_PROJECT_NAMESPACE.toLowerCase(); +var namespace = process.env.CI_PROJECT_NAMESPACE ? process.env.CI_PROJECT_NAMESPACE.replace(/[^a-zA-Z0-9]/g, '') : 'oecloudio'; +var name = process.env.CI_PROJECT_NAME ? process.env.CI_PROJECT_NAME.replace(/[^a-zA-Z0-9]/g, '') : 'oecloud'; + +var userName = namespace.toUpperCase() + '_' + name.toUpperCase(); +var password = namespace.toLowerCase(); var grants = [ 'CREATE VIEW', @@ -44,30 +51,32 @@ var grants = [ ]; function createUser(connection, cb) { - var sql = 'alter session set "_ORACLE_SCRIPT"=true'; - connection.execute(sql, function (e, r) { - if (e) { - console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + e); + var alterSQL = 'alter session set "_ORACLE_SCRIPT"=true'; + connection.execute(alterSQL, function (alterErr, alterRes) { + if (alterErr) { + console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + alterErr); } - console.log(sql, ' ......... ok'); - var sql = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + console.log(alterSQL, ' ......... ok'); - connection.execute(sql, function (err, result) { - if (err) { - throw new Error('Unable to create user ' + userName + ' Error :' + err); + var createUserSQL = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + connection.execute(createUserSQL, function (createErr, createRes) { + if (createErr) { + console.error(createErr); + throw new Error('Unable to create user ' + userName); } - console.log(sql, ' ......... ok'); - async.each(grants, function (g, callback) { - var sql = 'GRANT ' + g + ' to "' + userName + '"'; + console.log(createUserSQL, ' ......... ok'); - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute grant ' + sql); + async.each(grants, function (g, callback) { + var grantSQL = 'GRANT ' + g + ' to "' + userName + '"'; + connection.execute(grantSQL, function (grantErr, grantRes) { + if (grantErr) { + console.error(grantErr); + throw new Error('Unable to execute grant ' + grantSQL); } - console.log(sql, ' ......... ok'); + console.log(grantSQL, ' ......... ok'); return callback(); }); - }, function (err) { + }, function (grantAsyncErr) { console.log('User ' + userName + ' Created successfully'); return cb(); }); @@ -75,78 +84,83 @@ function createUser(connection, cb) { }); } - function dropTables(cb) { - var oracleConnectSettings2 = Object.assign({}, oracleConnectSettings); - oracleConnectSettings2.user = userName; - oracleConnectSettings2.password = password; - - oracledb.getConnection( - oracleConnectSettings2, - function (err, connection) { - if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + var oracleUserConnectSettings = { + 'password': password, + 'user': userName, + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID + }; + + oracledb.getConnection(oracleUserConnectSettings, function (userConnectionErr, connection) { + if (userConnectionErr) { + console.error(userConnectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleUserConnectSettings)); + } + + var totalRows = 1000; + var selectDropTableSQL = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; + connection.execute(selectDropTableSQL, {}, { maxRows: totalRows }, function (selectDropErr, selectDropRes) { + if (selectDropErr) { + console.error(selectDropErr); + throw new Error('Unable to find tables ' + userName); } - var sql = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; - var totalRows = 1000; - connection.execute(sql, {}, {maxRows: totalRows}, function (err, result) { - if (err) { - throw new Error('Unable to find tables ' + userName + ' Error :' + err); - } - connection.execute(sql, {}, {maxRows: totalRows}, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute droping of table ' + sql); - } - if (!result2 || !result2.rows || result2.rows.length === 0) { - return cb(); + if (!selectDropRes || !selectDropRes.rows || selectDropRes.rows.length === 0) { + return cb(); + } + + async.each(selectDropRes.rows, function (row, callback) { + var dropTableSQL = row[0]; + connection.execute(dropTableSQL, function (dropTableErr, dropTableRes) { + if (dropTableErr) { + console.error(dropTableErr); + throw new Error('Unable to drop table\nSQL: ' + sql); } - async.each(result2.rows, function (row, callback) { - var sql = row[0]; - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to drop table\nERROR : ' + err2 + '\nSQL : ' + sql); - } - console.log(sql, ' ......... ok'); - return callback(); - }); - }, function (err) { - console.log('Tables of user ' + userName + ' dropped successfully'); - return cb(); - }); + console.log(dropTableSQL, ' ......... ok'); + return callback(); }); + }, function (dropAsyncErr) { + console.log('Tables of user ' + userName + ' dropped successfully'); + return cb(); }); }); + }); } -oracledb.getConnection( - oracleConnectSettings, - function (err, connection) { +function generateUserBundle() { + console.log("Generating oracle user details shell script"); + fs.writeFileSync('./oracle-user.sh', '#!/bin/sh' + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_USERNAME=' + userName + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_PASSWORD=' + password + os.EOL); +} + +oracledb.getConnection(oracleConnectSettings, function (connectionErr, connection) { + if (connectionErr) { + console.error(connectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + } + var sql = "select username, user_id from dba_users where username = '" + userName + "'"; + console.log(sql); + connection.execute(sql, function (err, result) { if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + console.error(err); return; } - var sql = "select username, user_id from dba_users where username = '" + userName + "'"; - console.log(sql); - connection.execute(sql, - function (err, result) { + if (!result.rows || result.rows.length == 0) { + createUser(connection, function (err) { if (err) { - console.error(err); return; + return process.exit(1); } - if (!result.rows || result.rows.length == 0) { - createUser(connection, function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); - } else { - dropTables(function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); + generateUserBundle(); + return process.exit(); + }); + } else { + dropTables(function (err) { + if (err) { + return process.exit(1); } + generateUserBundle(); + return process.exit(); }); + } }); - +}); diff --git a/test/server.js b/test/server.js index 8f25bde..b45dafd 100755 --- a/test/server.js +++ b/test/server.js @@ -1,10 +1,10 @@ var oecloud = require('oe-cloud'); -var loopback=require('loopback'); -oecloud.attachMixinsToBaseEntity("SkeletonMixin"); +var loopback = require('loopback'); +oecloud.attachMixinsToBaseEntity('SkeletonMixin'); oecloud.observe('loaded', function (ctx, next) { return next(); -}) +}); oecloud.boot(__dirname, function (err) { oecloud.start(); diff --git a/test/test.js b/test/test.js index b23ee7b..5d4f506 100755 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,11 @@ var oecloud = require('oe-cloud'); var loopback = require('loopback'); -oecloud.attachMixinsToBaseEntity("SkeletonMixin"); +oecloud.attachMixinsToBaseEntity('SkeletonMixin'); oecloud.observe('loaded', function (ctx, next) { -console.log("oe-cloud modules loaded"); + console.log('oe-cloud modules loaded'); return next(); -}) +}); oecloud.boot(__dirname, function (err) { @@ -18,7 +18,6 @@ oecloud.boot(__dirname, function (err) { }); - var chalk = require('chalk'); var chai = require('chai'); var async = require('async'); @@ -35,7 +34,7 @@ var basePath = app.get('restApiRoot'); var url = basePath + '/Customers'; function deleteAllUsers(done) { - var userModel = loopback.findModel("User"); + var userModel = loopback.findModel('User'); userModel.destroyAll({}, {}, function (err) { return done(err); }); @@ -45,7 +44,7 @@ describe(chalk.blue('SkeletonTest Started'), function (done) { this.timeout(10000); before('wait for boot scripts to complete', function (done) { app.on('test-start', function () { - Customer = loopback.findModel("Customer"); + Customer = loopback.findModel('Customer'); deleteAllUsers(function (err) { return done(err); }); @@ -59,34 +58,33 @@ describe(chalk.blue('SkeletonTest Started'), function (done) { it('t1 create user admin/admin with /default tenant', function (done) { var url = basePath + '/users'; api.set('Accept', 'application/json') - .post(url) - .send([{ username: "admin", password: "admin", email: "admin@admin.com" }, - { username: "evuser", password: "evuser", email: "evuser@evuser.com" }, - { username: "infyuser", password: "infyuser", email: "infyuser@infyuser.com" }, - { username: "bpouser", password: "bpouser", email: "bpouser@bpouser.com" }]) - .end(function (err, response) { - - var result = response.body; - expect(result[0].id).to.be.defined; - expect(result[1].id).to.be.defined; - expect(result[2].id).to.be.defined; - expect(result[3].id).to.be.defined; - done(); - }); + .post(url) + .send([{ username: 'admin', password: 'admin', email: 'admin@admin.com' }, + { username: 'evuser', password: 'evuser', email: 'evuser@evuser.com' }, + { username: 'infyuser', password: 'infyuser', email: 'infyuser@infyuser.com' }, + { username: 'bpouser', password: 'bpouser', email: 'bpouser@bpouser.com' }]) + .end(function (err, response) { + var result = response.body; + expect(result[0].id).to.be.defined; + expect(result[1].id).to.be.defined; + expect(result[2].id).to.be.defined; + expect(result[3].id).to.be.defined; + done(); + }); }); var adminToken; it('t2 Login with admin credentials', function (done) { var url = basePath + '/users/login'; api.set('Accept', 'application/json') - .post(url) - .send({ username: "admin", password: "admin" }) - .end(function (err, response) { - var result = response.body; - adminToken = result.id; - expect(adminToken).to.be.defined; - done(); - }); + .post(url) + .send({ username: 'admin', password: 'admin' }) + .end(function (err, response) { + var result = response.body; + adminToken = result.id; + expect(adminToken).to.be.defined; + done(); + }); }); @@ -94,28 +92,28 @@ describe(chalk.blue('SkeletonTest Started'), function (done) { it('t3 Login with infy credentials', function (done) { var url = basePath + '/users/login'; api.set('Accept', 'application/json') - .post(url) - .send({ username: "infyuser", password: "infyuser" }) - .end(function (err, response) { - var result = response.body; - infyToken = result.id; - expect(infyToken).to.be.defined; - done(); - }); + .post(url) + .send({ username: 'infyuser', password: 'infyuser' }) + .end(function (err, response) { + var result = response.body; + infyToken = result.id; + expect(infyToken).to.be.defined; + done(); + }); }); var evToken; it('t4 Login with ev credentials', function (done) { var url = basePath + '/users/login'; api.set('Accept', 'application/json') - .post(url) - .send({ username: "evuser", password: "evuser" }) - .end(function (err, response) { - var result = response.body; - evToken = result.id; - expect(evToken).to.be.defined; - done(); - }); + .post(url) + .send({ username: 'evuser', password: 'evuser' }) + .end(function (err, response) { + var result = response.body; + evToken = result.id; + expect(evToken).to.be.defined; + done(); + }); }); @@ -123,18 +121,18 @@ describe(chalk.blue('SkeletonTest Started'), function (done) { it('t5 Login with bpo credentials', function (done) { var url = basePath + '/users/login'; api.set('Accept', 'application/json') - .post(url) - .send({ username: "bpouser", password: "bpouser" }) - .end(function (err, response) { - var result = response.body; - bpoToken = result.id; - expect(bpoToken).to.be.defined; - done(); - }); + .post(url) + .send({ username: 'bpouser', password: 'bpouser' }) + .end(function (err, response) { + var result = response.body; + bpoToken = result.id; + expect(bpoToken).to.be.defined; + done(); + }); }); it('t6 skeleton test case', function (done) { - var skeleton = loopback.findModel("Skeleton"); + var skeleton = loopback.findModel('Skeleton'); skeleton.find({}, {}, function (err, r) { return done(err); }); From a7ebb7ece807f2775612bb179be1062219766c0c Mon Sep 17 00:00:00 2001 From: vamsee Date: Thu, 23 Jan 2020 14:32:54 +0530 Subject: [PATCH 8/8] commit for version 2.2.0 --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 81cec90..ccd5eb6 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oe-skeleton", - "version": "2.1.0", + "version": "2.2.0", "description": "oe-cloud modularization project", "engines": { "node": ">=6" @@ -29,10 +29,10 @@ "grunt-mocha-istanbul": "5.0.2", "istanbul": "0.4.5", "mocha": "5.2.0", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", - "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", - "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#2.2.0", + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#2.2.0", + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#2.2.0", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#2.2.0", "superagent-defaults": "0.1.14", "supertest": "3.4.2" },