Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for Docker image #39

Merged
merged 1 commit into from Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ci/run_in_all_projects.sh
Expand Up @@ -2,6 +2,8 @@
TASK_TYPE=$1
CI_DIR_NAME=".ci"

set -e

echo "=== Task $TASK_TYPE ==="

echo "Setting environmental variables..."
Expand Down
14 changes: 10 additions & 4 deletions cli/test/integration/index.ts
Expand Up @@ -17,6 +17,11 @@ describe('CLI', () => {
});

it('should import data', async () => {
const dbConnectionUri = process.env.DB_URI
? process.env.DB_URI
: 'mongodb://127.0.0.1:27017/clidb';
const databaseName = process.env.DB_NAME ? process.env.DB_NAME : 'clidb';

const exit = jest
.spyOn(process, 'exit')
.mockImplementation(number => number);
Expand All @@ -27,14 +32,15 @@ describe('CLI', () => {
'--replace-id',
'--drop-collection',
'./test/integration/_importdata',
'--db-uri',
dbConnectionUri,
];

await run();

expect(console.error).not.toBeCalled();
expect(exit).toBeCalledWith(0);

const dbConnectionUri = process.env.DB_URI
? process.env.DB_URI
: 'mongodb://127.0.0.1:27017/database';
const databaseName = process.env.DB_NAME ? process.env.DB_NAME : 'database';
const client = await MongoClient.connect(
dbConnectionUri,
{ ignoreUndefined: true, useNewUrlParser: true },
Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/Database.ts
Expand Up @@ -13,7 +13,7 @@ beforeAll(async () => {
database = await databaseConnector.connect({
databaseConfig: {
...defaultConfig.database,
name: 'Database',
name: 'coredb',
},
});
await database.db.dropDatabase();
Expand Down
5 changes: 4 additions & 1 deletion core/test/integration/DatabaseConnector.ts
Expand Up @@ -8,7 +8,10 @@ describe('DatabaseConnector', () => {
const databaseConnector = new DatabaseConnector();

const database = await databaseConnector.connect({
databaseConfig: defaultConfig.database,
databaseConfig: {
...defaultConfig.database,
name: 'coredb',
},
});
const collections = await database.db.listCollections().toArray();

Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/index.ts
Expand Up @@ -5,7 +5,7 @@ import { defaultConfig, DeepPartial, AppConfig } from '../../src/common';
import { seedDatabase } from '../../src';
import { listExistingCollections, createCollection } from '../_helpers';

const DATABASE_NAME = 'seedDatabase';
const DATABASE_NAME = 'coredb';
const TEMP_DIRECTORY_PATH = __dirname + '/.temp-seedDatabase';

const databaseConnector = new DatabaseConnector();
Expand Down
14 changes: 14 additions & 0 deletions docker-image/.ci/script.sh
Expand Up @@ -3,4 +3,18 @@
echo "Building image..."
cd ./docker-image
./build.sh $DOCKER_IMAGE_REPOSITORY:$CI_BUILD_NUMBER

DATA_IMPORT_PATH="$(pwd)/test/_importdata"
TESTER_IMAGE_NAME="tester:latest"
DB_NAME=dockerdb

# Import data
docker run --rm -it --network="host" -e DB_NAME=${DB_NAME} -e REPLACE_ID=true -v ${DATA_IMPORT_PATH}:${DATA_IMPORT_PATH} -w ${DATA_IMPORT_PATH} $DOCKER_IMAGE_REPOSITORY:$CI_BUILD_NUMBER
# Build & run tester
cd ./test/tester
docker build -t ${TESTER_IMAGE_NAME} .
docker run --rm -it --network="host" -e DB_NAME=${DB_NAME} ${TESTER_IMAGE_NAME}
cd ../..


cd ..
4 changes: 4 additions & 0 deletions docker-image/test/_importdata/cliarrays/1-array.js
@@ -0,0 +1,4 @@
module.exports = [
{ id: 'onetest', number: 1, name: 'one' },
{ id: 'fivetest', number: 5, name: 'five' },
];
1 change: 1 addition & 0 deletions docker-image/test/_importdata/cliarrays/2-array.ts
@@ -0,0 +1 @@
export = [{ number: 2, name: 'two' }, { number: 4, name: 'four' }];
4 changes: 4 additions & 0 deletions docker-image/test/_importdata/cliarrays/3-array.json
@@ -0,0 +1,4 @@
[
{ "id": "threetest", "number": 3, "name": "three" },
{ "number": 6, "name": "six" }
]
5 changes: 5 additions & 0 deletions docker-image/test/_importdata/cliobjects/1-obj.json
@@ -0,0 +1,5 @@
{
"id": "onetest",
"number": 1,
"name": "one"
}
4 changes: 4 additions & 0 deletions docker-image/test/_importdata/cliobjects/2-obj.js
@@ -0,0 +1,4 @@
module.exports = {
number: 2,
name: 'two',
};
5 changes: 5 additions & 0 deletions docker-image/test/_importdata/cliobjects/3-obj.ts
@@ -0,0 +1,5 @@
export = {
id: 'threetest',
number: 3,
name: 'three',
};
5 changes: 5 additions & 0 deletions docker-image/test/tester/.dockerignore
@@ -0,0 +1,5 @@
/**/.ci/
/**/node_modules/
/**/coverage/
*.log
.DS_Store
13 changes: 13 additions & 0 deletions docker-image/test/tester/Dockerfile
@@ -0,0 +1,13 @@
FROM node:10.10.0-alpine

WORKDIR /app

COPY ./package.json ./package-lock.json /app/

RUN npm install --no-optional

COPY ./src /app/src

ENV CI true

CMD npm test