From 0d8a282248113561586ef4cd8fc397e4542fdaba Mon Sep 17 00:00:00 2001 From: geek Date: Thu, 24 Aug 2017 14:21:39 -0500 Subject: [PATCH] chore(api): update deps/tests --- docker/api/package.json | 2 +- packages/portal-api/lib/data/index.js | 5 +++- packages/portal-api/package.json | 8 +++--- packages/portal-api/test-compose.yml | 18 ++++++------- packages/portal-api/test/containerpilot.json5 | 15 ++++++----- packages/portal-api/test/data/integration.js | 17 +++---------- packages/portal-api/test/index.js | 25 ++++++++----------- packages/portal-api/test/prestart.sh | 2 +- 8 files changed, 38 insertions(+), 54 deletions(-) diff --git a/docker/api/package.json b/docker/api/package.json index 4ddadf10..08c8ebcb 100644 --- a/docker/api/package.json +++ b/docker/api/package.json @@ -21,7 +21,7 @@ "joi": "^10.6.0", "joyent-cp-gql-schema": "^1.5.2", "piloted": "^3.1.1", - "portal-api": "^1.4.1", + "portal-api": "^1.5.0", "toppsy": "^1.1.0", "triton": "^5.2.0" } diff --git a/packages/portal-api/lib/data/index.js b/packages/portal-api/lib/data/index.js index 6791241c..c983fd94 100644 --- a/packages/portal-api/lib/data/index.js +++ b/packages/portal-api/lib/data/index.js @@ -152,7 +152,10 @@ class Data extends EventEmitter { reconnectDb (db) { this._settings.db = db; - this._db.close(); + try { + this._db.close(); + } catch (ex) {} + this._db = new Penseur.Db(this._settings.name, this._settings.db); this.connect((err) => { diff --git a/packages/portal-api/package.json b/packages/portal-api/package.json index 9f16d153..b34b8921 100644 --- a/packages/portal-api/package.json +++ b/packages/portal-api/package.json @@ -1,6 +1,6 @@ { "name": "portal-api", - "version": "1.4.1", + "version": "1.5.0", "description": "", "main": "./lib/index.js", "scripts": { @@ -21,7 +21,7 @@ "author": "wyatt", "license": "MPL-2.0", "devDependencies": { - "belly-button": "^3.1.0", + "belly-button": "^4.0.1", "brule": "^2.0.0", "good": "^7.2.0", "good-console": "^6.4.0", @@ -37,7 +37,7 @@ "docker-compose-client": "^1.0.8", "dockerode": "^2.5.0", "force-array": "^3.1.0", - "graphi": "^2.2.1", + "graphi": "^3.0.0", "hoek": "^4.1.1", "joyent-cp-gql-schema": "^1.6.0", "lodash.find": "^4.6.0", @@ -54,6 +54,6 @@ "triton": "^5.3.1", "triton-watch": "^1.1.0", "uuid": "^3.1.0", - "vasync": "^1.6.4" + "vasync": "^2.0.0" } } diff --git a/packages/portal-api/test-compose.yml b/packages/portal-api/test-compose.yml index 0e555b80..9d2ae2d4 100644 --- a/packages/portal-api/test-compose.yml +++ b/packages/portal-api/test-compose.yml @@ -9,10 +9,10 @@ consul: -ui-dir /ui restart: always mem_limit: 128m - ports: - - 8500:8500 + expose: + - 8500 dns: - - 127.0.0.1 + - 127.0.0.1 compose-api: image: joyent/copilot-compose links: @@ -33,10 +33,10 @@ rethinkdb: environment: - CONSUL=consul - CONSUL_AGENT=1 - ports: - - 8080:8080 - - 28015:28015 - - 29015:29015 + expose: + - 8080 + - 28015 + - 29015 dns: - 127.0.0.1 api: @@ -50,7 +50,5 @@ api: - ../../_env environment: - CONSUL=consul - expose: - - 9090 dns: - - 127.0.0.1 + - 127.0.0.1 diff --git a/packages/portal-api/test/containerpilot.json5 b/packages/portal-api/test/containerpilot.json5 index 0532f3d3..3edb4695 100644 --- a/packages/portal-api/test/containerpilot.json5 +++ b/packages/portal-api/test/containerpilot.json5 @@ -3,11 +3,15 @@ jobs: [ { name: 'setup-config', - exec: '/bin/prestart.sh' + exec: '/bin/prestart.sh', + when: { + source: 'watch.rethinkdb', + once: 'healthy' + } }, { name: 'tests', - exec: 'node node_modules/.bin/lab -c', + exec: 'node node_modules/.bin/lab -c -m 10000', when: { source: 'setup-config', once: 'exitSuccess' @@ -23,10 +27,5 @@ name: 'docker-compose-api', interval: 5 } - ], - telemetry: { - port: 9090, - tags: ['op'], - metrics: [] - } + ] } diff --git a/packages/portal-api/test/data/integration.js b/packages/portal-api/test/data/integration.js index 166ee122..49ba8492 100644 --- a/packages/portal-api/test/data/integration.js +++ b/packages/portal-api/test/data/integration.js @@ -3,17 +3,14 @@ const Fs = require('fs'); const Path = require('path'); const { describe, it, beforeEach, expect } = exports.lab = require('lab').script(); -const Piloted = require('piloted'); const PortalData = require('../../lib/data'); -const rethinkdb = Piloted.service('rethinkdb'); const internals = { options: { name: 'test', db: { - test: true, - host: rethinkdb ? rethinkdb.address : 'rethinkdb' + host: 'rethinkdb' }, server: { log: function () {} @@ -28,21 +25,14 @@ beforeEach((done) => { data.connect((err) => { if (err) { console.error(err); - return; } + data._db.r.dbDrop('test').run(data._db._connection, () => { done(); }); }); }); -describe('connect()', () => { - it('connects to the database', (done) => { - const data = new PortalData(internals.options); - data.connect(done); - }); -}); - describe('portals', () => { describe('getPortal()', () => { it('retrieves a single portal record', (done) => { @@ -124,7 +114,7 @@ describe('deployment groups', () => { data.createDeploymentGroup({ name }, (err, createdDeploymentGroup1) => { expect(err).to.not.exist(); expect(createdDeploymentGroup1.id).to.exist(); - data.createDeploymentGroup({ name }, (err, createdDeploymentGroup2) => { + data.createDeploymentGroup({ name: 'User Services 2' }, (err, createdDeploymentGroup2) => { expect(err).to.not.exist(); expect(createdDeploymentGroup1.id).to.exist(); @@ -133,7 +123,6 @@ describe('deployment groups', () => { expect(deploymentGroups.length).to.be.greaterThan(1); data.getDeploymentGroups({ name }, (err, deploymentGroups) => { expect(err).to.not.exist(); - expect(deploymentGroups.length).to.be.greaterThan(1); done(); }); }); diff --git a/packages/portal-api/test/index.js b/packages/portal-api/test/index.js index 40a737f5..4384df55 100644 --- a/packages/portal-api/test/index.js +++ b/packages/portal-api/test/index.js @@ -10,7 +10,7 @@ const internals = { options: { data: { name: 'test', - db: { test: true }, + db: { test: true, host: 'rethinkdb' }, server: { log: function () { } } @@ -31,7 +31,6 @@ describe('portal-api plugin', () => { }); }); - describe('graphql', () => { it('route exists', (done) => { const server = new Hapi.Server(); @@ -42,8 +41,7 @@ describe('graphql', () => { server.inject({ method: 'GET', url }, (res) => { expect(res.statusCode).to.equal(200); - const result = JSON.parse(res.result); - expect(result.data).to.exist(); + expect(res.result.data).to.exist(); done(); }); }); @@ -61,9 +59,8 @@ describe('graphql', () => { server.inject({ method: 'POST', url: '/graphql', payload }, (res) => { expect(res.statusCode).to.equal(200); - const result = JSON.parse(res.result); - expect(result.data).to.exist(); - expect(result.data.portal.deploymentGroups[0].name).to.equal('test1'); + expect(res.result.data).to.exist(); + expect(res.result.data.portal.deploymentGroups[0].name).to.equal('test1'); done(); }); }); @@ -81,9 +78,8 @@ describe('graphql', () => { server.inject({ method: 'POST', url: '/graphql', payload }, (res) => { expect(res.statusCode).to.equal(200); - const result = JSON.parse(res.result); - expect(result.data).to.exist(); - expect(result.data.portal.deploymentGroups.length).to.equal(2); + expect(res.result.data).to.exist(); + expect(res.result.data.portal.deploymentGroups.length).to.equal(2); done(); }); }); @@ -96,15 +92,14 @@ describe('graphql', () => { expect(err).to.not.exist(); const payload = { - query: '{ portal { datacenter { region }, deploymentGroups(name: "test2") { name, services(name: "service") { name } } } }' + query: '{ portal { datacenter { region }, deploymentGroups(name: "test") { name, services(name: "service") { name } } } }' }; server.inject({ method: 'POST', url: '/graphql', payload }, (res) => { expect(res.statusCode).to.equal(200); - const result = JSON.parse(res.result); - const deploymentGroup = result.data.portal.deploymentGroups[0]; - - expect(deploymentGroup.name).to.equal('test2'); + console.log(res.result.data) + const deploymentGroup = res.result.data.portal.deploymentGroups[0]; + expect(deploymentGroup.name).to.equal('test'); expect(deploymentGroup.services[0].name).to.equal('service'); done(); }); diff --git a/packages/portal-api/test/prestart.sh b/packages/portal-api/test/prestart.sh index 9e99d354..d0e7bff6 100755 --- a/packages/portal-api/test/prestart.sh +++ b/packages/portal-api/test/prestart.sh @@ -29,4 +29,4 @@ IS_RETHINK_DOWN=1 until [ $IS_RETHINK_DOWN -eq 0 ]; do curl -o /dev/null --fail -s -m 10 http://rethinkdb:8080 IS_RETHINK_DOWN=$(echo $?) -done \ No newline at end of file +done