Browse Source

Merge pull request #55 from bvkatwijk/add_docker_compose

Add docker compose
pull/56/head
o1lab 6 years ago committed by GitHub
parent
commit
8ff7382545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      README.md
  2. 20
      dev.Dockerfile
  3. 38
      docker-compose.yml
  4. 3
      docker-entrypoint.sh
  5. 7946
      tests/docker-sample.sql
  6. 118
      tests/tests.js

13
README.md

@ -1065,16 +1065,7 @@ When you start your nginx proxy in a docker container too, use as `proxy_pass` t
# Tests : setup on local machine
[:arrow_heading_up:](#api-overview)
Login to mysql shell
```
mysql> create database classicmodels
mysql> use classicmodels
mysql> source path_to/xmysql/tests/sample.sql
```
```
$ mocha tests/*.js --exit
docker-compose run test
```
* Requires `docker-compose` to be installed on your machine.

20
dev.Dockerfile

@ -0,0 +1,20 @@
FROM frolvlad/alpine-python2
RUN apk --update --no-cache add \
g++ \
make \
nodejs \
nodejs-npm \
paxctl \
&& paxctl -cm $(which node)
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["sh", "-c", "node index.js -h $DATABASE_HOST -p $DATABASE_PASSWORD -d $DATABASE_NAME -u $DATABASE_USER -n 80 -r 0.0.0.0"]

38
docker-compose.yml

@ -0,0 +1,38 @@
version: '3.5'
services:
db:
image: mysql:5.7
restart: always
command: --init-file /docker-entrypoint-initdb.d/sample.sql
environment:
MYSQL_ROOT_PASSWORD: 'pass'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'pass'
MYSQL_DATABASE: 'classicmodels'
volumes:
- ./tests/docker-sample.sql:/docker-entrypoint-initdb.d/sample.sql
- db-data:/var/lib/mysql
ports:
- "3306:3306"
db-api: &db-api
build:
context: ./
dockerfile: ./dev.Dockerfile
environment:
DATABASE_HOST: 'db'
DATABASE_USER: 'root'
DATABASE_PASSWORD: 'pass'
DATABASE_NAME: 'classicmodels'
ports:
- "3002:80"
depends_on:
- db
test:
<<: *db-api
command: sh -c "npm test"
volumes:
db-data:

3
docker-entrypoint.sh

@ -12,5 +12,4 @@ done
echo "Mysql is up - executing command"
cd /usr/src/app/
node index.js -h $DATABASE_HOST -p $DATABASE_PASSWORD -d $DATABASE_NAME -u $DATABASE_USER -n 80 -r 0.0.0.0
exec "$@"

7946
tests/docker-sample.sql

File diff suppressed because it is too large Load Diff

118
tests/tests.js

@ -23,10 +23,10 @@ describe('xmysql : tests', function () {
before(function (done) {
args['host'] = 'localhost'
args['user'] = 'root'
args['password'] = ''
args['database'] = 'classicmodels'
args['host'] = process.env.DATABASE_HOST || 'localhost'
args['user'] = process.env.DATABASE_USER || 'root'
args['password'] = process.env.DATABASE_PASSWORD || ''
args['database'] = process.env.DATABASE_NAME || 'classicmodels'
args['apiPrefix'] = apiPrefix
cmdargs.handle(args)
@ -697,82 +697,84 @@ describe('xmysql : tests', function () {
});
});
it('POST /dynamic should PASS', function (done) {
if(args['host'] === 'localhost') {
it('POST /dynamic should PASS', function (done) {
var obj = {};
var obj = {};
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
res.body.length.should.be.equals(5)
//validate response
res.body.length.should.be.equals(5)
return done();
return done();
});
});
});
});
it('POST /dynamic/abc should PASS', function (done) {
it('POST /dynamic/abc should PASS', function (done) {
var obj = {};
var obj = {};
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
//validate response
res.body.length.should.be.equals(5)
res.body.length.should.be.equals(5)
return done();
return done();
});
});
});
});
it('POST /dynamic should PASS', function (done) {
it('POST /dynamic should PASS', function (done) {
var obj = {};
var obj = {};
obj['query'] = 'select * from customers limit 0,5'
obj['params'] = []
obj['query'] = 'select * from customers limit 0,5'
obj['params'] = []
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
//validate response
res.body.length.should.be.equals(5)
res.body.length.should.be.equals(5)
return done();
return done();
});
});
});
});
}
it('PATCH /api/productlines/Hyperloop should PASS', function (done) {

Loading…
Cancel
Save