diff --git a/.travis.yml b/.travis.yml index e667b9209..d38f7e60a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: - - 'iojs' + - 'iojs-v2' + - 'iojs-v1' - '0.12' - '0.10' diff --git a/package.json b/package.json index 2b1a7be35..89ae17e83 100644 --- a/package.json +++ b/package.json @@ -80,14 +80,13 @@ "then-redis": "~1.3.0", "trace": "^1.2.0", "ws": "~0.7.1", - "xen-api": "^0.5.4", + "xen-api": "^0.5.6", "xml2js": "~0.4.6", "xo-collection": "^0.3.2" }, "devDependencies": { "babel-eslint": "^3.1.9", "babel-plugin-closure-elimination": "0.0.1", - "chai": "~2.1.2", "dependency-check": "^2.4.0", "gulp": "git://github.com/gulpjs/gulp#4.0", "gulp-babel": "^5", @@ -96,6 +95,7 @@ "gulp-sourcemaps": "^1.5.1", "gulp-watch": "^4.2.2", "mocha": "^2.2.1", + "must": "^0.12.0", "node-inspector": "^0.10.1", "sinon": "^1.14.1", "standard": "^4.0.0" @@ -106,7 +106,7 @@ "lint": "standard", "prepublish": "npm run build", "start": "node bin/xo-server", - "test": "npm run lint && dependency-check ./package.json && mocha --opts .mocha.opts 'dist/**/*.spec.js'" + "test": "npm run lint && dependency-check ./package.json && mocha --opts .mocha.opts \"dist/**/*.spec.js\"" }, "standard": { "ignore": [ diff --git a/src/api/token.js b/src/api/token.js index 516d1788b..40df4be70 100644 --- a/src/api/token.js +++ b/src/api/token.js @@ -1,7 +1,3 @@ -import {Unauthorized} from '../api-errors' - -// =================================================================== - // TODO: Prevent token connections from creating tokens. // TODO: Token permission. export async function create () { diff --git a/src/decorators.spec.js b/src/decorators.spec.js index 376477045..ea555ea0b 100644 --- a/src/decorators.spec.js +++ b/src/decorators.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import {expect} from 'chai' +import expect from 'must' // =================================================================== diff --git a/src/index.js b/src/index.js index ad577197f..8d23bfe9f 100644 --- a/src/index.js +++ b/src/index.js @@ -447,10 +447,18 @@ export default async function main (args) { info('Default user created:', email, ' with password', password) } - // Handle gracefully shutdown. - const closeWebServer = () => { webServer.close() } - process.on('SIGINT', closeWebServer) - process.on('SIGTERM', closeWebServer) + // Gracefully shutdown on signals. + // + // TODO: implements a timeout? (or maybe it is the services launcher + // responsability?) + process.on('SIGINT', () => { + debug('SIGINT caught, closing web server…') + webServer.close() + }) + process.on('SIGTERM', () => { + debug('SIGTERM caught, closing web server…') + webServer.close() + }) return eventToPromise(webServer, 'close') } diff --git a/src/utils.spec.js b/src/utils.spec.js index fb148c7e2..38142afff 100644 --- a/src/utils.spec.js +++ b/src/utils.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import {expect} from 'chai' +import expect from 'must' // =================================================================== @@ -12,6 +12,12 @@ import { // =================================================================== describe('ensureArray', function () { + it('wrap the value in an array', function () { + const value = 'foo' + + expect(ensureArray(value)).to.eql([value]) + }) + it('returns an empty array for undefined', function () { expect(ensureArray(undefined)).to.eql([]) }) @@ -21,12 +27,6 @@ describe('ensureArray', function () { expect(ensureArray(array)).to.equal(array) }) - - it('wrap the value in an object', function () { - const value = {} - - expect(ensureArray(value)).to.includes(value) - }) }) // ------------------------------------------------------------------- diff --git a/src/xapi.js b/src/xapi.js index 123b2e4b3..01203c471 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -7,7 +7,10 @@ import map from 'lodash.map' import unzip from 'julien-f-unzip' import {PassThrough} from 'stream' import {promisify} from 'bluebird' -import {Xapi as XapiBase} from 'xen-api' +import { + wrapError as wrapXapiError, + Xapi as XapiBase +} from 'xen-api' import {debounce} from './decorators' import {ensureArray, noop, parseXml, pFinally} from './utils' @@ -19,13 +22,6 @@ const debug = createDebug('xo:xapi') const gotPromise = promisify(got) -const wrapError = error => { - const e = new Error(error[0]) - e.code = error[0] - e.params = error.slice(1) - return e -} - // =================================================================== const typeToNamespace = Object.create(null) @@ -107,7 +103,7 @@ export default class Xapi extends XapiBase { if (status === 'success') { taskWatchers[ref].resolve(object.result) } else if (status === 'failure') { - taskWatchers[ref].reject(wrapError(object.error_info)) + taskWatchers[ref].reject(wrapXapiError(object.error_info)) } else { return }