mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
feat: utilize api-cli for e2e integration test
This commit is contained in:
committed by
Rainer Killinger
parent
bbbe4d5f1f
commit
ce06e735be
@@ -3,6 +3,7 @@ image: registry.gitlab.com/openstapps/projectmanagement/node
|
|||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- test
|
- test
|
||||||
|
- audit
|
||||||
- publish
|
- publish
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
@@ -16,15 +17,30 @@ build:
|
|||||||
paths:
|
paths:
|
||||||
- node_modules/
|
- node_modules/
|
||||||
|
|
||||||
test:
|
unit:
|
||||||
stage: test
|
stage: test
|
||||||
dependencies:
|
dependencies:
|
||||||
- build
|
- build
|
||||||
script:
|
script:
|
||||||
- npm run test
|
- npm run test-unit
|
||||||
|
|
||||||
audit:
|
integration:
|
||||||
|
image: registry.gitlab.com/openstapps/projectmanagement/builder
|
||||||
stage: test
|
stage: test
|
||||||
|
dependencies:
|
||||||
|
- build
|
||||||
|
variables:
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
|
script:
|
||||||
|
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
|
||||||
|
- docker-compose -f integration-test.yml pull && docker-compose -f integration-test.yml up --abort-on-container-exit --exit-code-from apicli
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
audit:
|
||||||
|
stage: audit
|
||||||
dependencies:
|
dependencies:
|
||||||
- build
|
- build
|
||||||
script:
|
script:
|
||||||
@@ -45,13 +61,13 @@ pages:
|
|||||||
- public
|
- public
|
||||||
|
|
||||||
scheduled-audit:
|
scheduled-audit:
|
||||||
stage: test
|
stage: audit
|
||||||
script:
|
script:
|
||||||
- npm audit
|
- npm audit
|
||||||
only:
|
only:
|
||||||
- schedules
|
- schedules
|
||||||
|
|
||||||
test:ci:
|
ci:
|
||||||
stage: test
|
stage: test
|
||||||
dependencies:
|
dependencies:
|
||||||
- build
|
- build
|
||||||
|
|||||||
26
integration-test.yml
Normal file
26
integration-test.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
build: .
|
||||||
|
environment:
|
||||||
|
STAPPS_LOG_LEVEL: "31"
|
||||||
|
STAPPS_EXIT_LEVEL: "8"
|
||||||
|
NODE_CONFIG_ENV: "elasticsearch"
|
||||||
|
NODE_ENV: "integration-test"
|
||||||
|
ALLOW_NO_TRANSPORT: "true"
|
||||||
|
ES_FORCE_MAPPING_UPDATE: "true"
|
||||||
|
ES_ADDR: "http://elasticsearch:9200"
|
||||||
|
|
||||||
|
elasticsearch:
|
||||||
|
ports:
|
||||||
|
- "9200:9200"
|
||||||
|
image: "registry.gitlab.com/openstapps/database:master"
|
||||||
|
|
||||||
|
apicli:
|
||||||
|
image: "registry.gitlab.com/openstapps/api/cli:latest"
|
||||||
|
environment:
|
||||||
|
STAPPS_LOG_LEVEL: "31"
|
||||||
|
STAPPS_EXIT_LEVEL: "8"
|
||||||
|
command: e2e http://backend:3000 --waiton tcp:backend:3000
|
||||||
1727
package-lock.json
generated
1727
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -25,8 +25,10 @@
|
|||||||
"preversion": "npm run prepublishOnly",
|
"preversion": "npm run prepublishOnly",
|
||||||
"push": "git push && git push origin \"v$npm_package_version\"",
|
"push": "git push && git push origin \"v$npm_package_version\"",
|
||||||
"start": "NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node ./lib/cli.js",
|
"start": "NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node ./lib/cli.js",
|
||||||
"start-debug": "NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true ES_FORCE_MAPPING_UPDATE=true node ./lib/cli.js --require ts-node/register",
|
"start-debug": "STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true ES_FORCE_MAPPING_UPDATE=true node ./lib/cli.js --require ts-node/register",
|
||||||
"test": "env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true ES_FORCE_MAPPING_UPDATE=true nyc mocha --require ts-node/register --exit 'test/**/*.spec.ts'",
|
"test": "npm run test-unit && npm run test-integration",
|
||||||
|
"test-unit": "env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true ES_FORCE_MAPPING_UPDATE=true nyc mocha --require ts-node/register --exit 'test/**/*.spec.ts'",
|
||||||
|
"test-integration": "sudo docker-compose -f integration-test.yml pull && sudo docker-compose -f integration-test.yml up --build --abort-on-container-exit --exit-code-from apicli",
|
||||||
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
|
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
23
src/app.ts
23
src/app.ts
@@ -44,8 +44,29 @@ import {Elasticsearch} from './storage/elasticsearch/elasticsearch';
|
|||||||
* Configure the backend
|
* Configure the backend
|
||||||
*/
|
*/
|
||||||
export async function configureApp(app: Express) {
|
export async function configureApp(app: Express) {
|
||||||
|
let integrationTestTimeout: NodeJS.Timeout;
|
||||||
// request loggers have to be the first middleware to be set in express
|
// request loggers have to be the first middleware to be set in express
|
||||||
app.use(morgan('dev'));
|
app.use(morgan('dev', {
|
||||||
|
skip: (_req, res) => {
|
||||||
|
if (process.env.NODE_ENV === 'integration-test') {
|
||||||
|
clearTimeout(integrationTestTimeout);
|
||||||
|
integrationTestTimeout = setTimeout(() => {
|
||||||
|
process.exit(1);
|
||||||
|
},
|
||||||
|
// tslint:disable-next-line:no-magic-numbers
|
||||||
|
20000);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line: no-magic-numbers
|
||||||
|
if (res.statusCode < 400) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}, stream: process.stdout,
|
||||||
|
}));
|
||||||
|
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
allowedHeaders: [
|
allowedHeaders: [
|
||||||
|
|||||||
@@ -34,9 +34,8 @@ app.set('port', port);
|
|||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen on provided port, on all network interfaces.
|
* Define server handling for specific events
|
||||||
*/
|
*/
|
||||||
server.listen(port);
|
|
||||||
server.on('error', onError);
|
server.on('error', onError);
|
||||||
server.on('listening', onListening);
|
server.on('listening', onListening);
|
||||||
|
|
||||||
@@ -101,6 +100,8 @@ function onListening() {
|
|||||||
configureApp(app)
|
configureApp(app)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Logger.ok('Sucessfully configured express server');
|
Logger.ok('Sucessfully configured express server');
|
||||||
|
// After app setup listen on provided port, on all network interfaces
|
||||||
|
server.listen(port);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
|
|||||||
);
|
);
|
||||||
res.status(error.statusCode);
|
res.status(error.statusCode);
|
||||||
res.json(error);
|
res.json(error);
|
||||||
Logger.warn(error);
|
await Logger.error(error);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
|
|||||||
);
|
);
|
||||||
res.status(internalServerError.statusCode);
|
res.status(internalServerError.statusCode);
|
||||||
res.json(internalServerError);
|
res.json(internalServerError);
|
||||||
Logger.warn(internalServerError);
|
await Logger.error(internalServerError);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
|
|||||||
// respond with the error from the handler
|
// respond with the error from the handler
|
||||||
res.status(error.statusCode);
|
res.status(error.statusCode);
|
||||||
res.json(error);
|
res.json(error);
|
||||||
Logger.warn(error);
|
await Logger.error(error);
|
||||||
} else {
|
} else {
|
||||||
// the error is not allowed so something went wrong
|
// the error is not allowed so something went wrong
|
||||||
const internalServerError = new SCInternalServerErrorResponse(
|
const internalServerError = new SCInternalServerErrorResponse(
|
||||||
|
|||||||
Reference in New Issue
Block a user