2015-09-01 10:31:00 +03:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Joyent, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test helpers for the integration tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
var error = console.error;
|
|
|
|
var assert = require('assert-plus');
|
2015-09-29 21:45:34 +03:00
|
|
|
var f = require('util').format;
|
2015-09-01 10:31:00 +03:00
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var testcommon = require('../lib/testcommon');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- globals
|
|
|
|
|
|
|
|
try {
|
|
|
|
var CONFIG = require('../config.json');
|
|
|
|
assert.object(CONFIG, 'test/config.json');
|
|
|
|
assert.string(CONFIG.url, 'test/config.json#url');
|
|
|
|
assert.string(CONFIG.account, 'test/config.json#account');
|
2015-09-25 20:08:00 +03:00
|
|
|
assert.string(CONFIG.keyId, 'test/config.json#keyId');
|
2015-09-22 01:48:03 +03:00
|
|
|
if (CONFIG.insecure === undefined)
|
|
|
|
CONFIG.insecure = false;
|
2015-09-25 20:13:39 +03:00
|
|
|
if (CONFIG.destructiveAllowed === undefined)
|
|
|
|
CONFIG.destructiveAllowed = false;
|
|
|
|
assert.bool(CONFIG.insecure, 'test/config.json#destructiveAllowed');
|
2015-09-01 10:31:00 +03:00
|
|
|
} catch (e) {
|
|
|
|
error('* * *');
|
|
|
|
error('node-triton integration tests require a ./test/config.json');
|
|
|
|
error('');
|
|
|
|
error(' {');
|
|
|
|
error(' "url": "<CloudAPI URL>",');
|
|
|
|
error(' "account": "<account>",');
|
2015-09-25 20:08:00 +03:00
|
|
|
error(' "keyId": "<ssh key fingerprint>",');
|
2015-09-25 20:24:12 +03:00
|
|
|
error(' "insecure": true|false, // optional');
|
|
|
|
error(' "destructiveAllowed": true|false // optional');
|
2015-09-01 10:31:00 +03:00
|
|
|
error(' }');
|
|
|
|
error('');
|
|
|
|
error('Note: This test suite with create machines, images, et al using');
|
|
|
|
error('this CloudAPI and account. That could *cost* you money. :)');
|
|
|
|
error('* * *');
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2015-09-22 01:48:03 +03:00
|
|
|
var TRITON = [process.execPath, path.resolve(__dirname, '../../bin/triton')];
|
2015-09-01 10:31:00 +03:00
|
|
|
var UA = 'node-triton-test';
|
|
|
|
|
|
|
|
var LOG = require('../lib/log');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- internal support routines
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the `triton` CLI with the given args.
|
|
|
|
*/
|
|
|
|
function triton(args, cb) {
|
2015-09-22 01:48:03 +03:00
|
|
|
var command = [].concat(TRITON).concat(args);
|
|
|
|
if (typeof (args) === 'string')
|
|
|
|
command = command.join(' ');
|
|
|
|
|
2015-09-01 10:31:00 +03:00
|
|
|
testcommon.execPlus({
|
2015-09-22 01:48:03 +03:00
|
|
|
command: command,
|
2015-09-01 10:31:00 +03:00
|
|
|
execOpts: {
|
|
|
|
maxBuffer: Infinity,
|
|
|
|
env: {
|
|
|
|
PATH: process.env.PATH,
|
|
|
|
HOME: process.env.HOME,
|
2015-09-22 01:48:03 +03:00
|
|
|
SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK,
|
2015-09-25 20:10:39 +03:00
|
|
|
TRITON_PROFILE: 'env',
|
2015-09-25 20:24:12 +03:00
|
|
|
TRITON_URL: CONFIG.url,
|
|
|
|
TRITON_ACCOUNT: CONFIG.account,
|
|
|
|
TRITON_KEY_ID: CONFIG.keyId,
|
|
|
|
TRITON_TLS_INSECURE: CONFIG.insecure
|
2015-09-01 10:31:00 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
log: LOG
|
|
|
|
}, cb);
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:45:34 +03:00
|
|
|
/*
|
|
|
|
* triton wrapper that:
|
|
|
|
* - tests no error is present
|
|
|
|
* - tests stdout is not empty
|
|
|
|
* - tests stderr is empty
|
|
|
|
*
|
|
|
|
* In the event that any of the above is false, this function will NOT
|
|
|
|
* fire the callback, which will result in the early terminate of these
|
|
|
|
* tests as `t.end()` will never be called.
|
|
|
|
*
|
|
|
|
* @param {Tape} t - tape test object
|
|
|
|
* @param {Object|Array} opts - options object
|
|
|
|
* @param {Function} cb - callback called like "cb(stdout)"
|
|
|
|
*/
|
|
|
|
function safeTriton(t, opts, cb) {
|
|
|
|
if (Array.isArray(opts)) {
|
|
|
|
opts = {args: opts};
|
|
|
|
}
|
|
|
|
t.comment(f('running: triton %s', opts.args.join(' ')));
|
|
|
|
triton(opts.args, function (err, stdout, stderr) {
|
|
|
|
t.error(err, 'no error running child process');
|
|
|
|
t.equal(stderr, '', 'no stderr produced');
|
|
|
|
t.notEqual(stdout, '', 'stdout produced');
|
|
|
|
|
|
|
|
if (opts.json) {
|
|
|
|
try {
|
|
|
|
stdout = JSON.parse(stdout);
|
|
|
|
} catch (e) {
|
|
|
|
t.fail('failed to parse JSON');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err && stdout && !stderr)
|
|
|
|
cb(stdout);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-01 10:31:00 +03:00
|
|
|
|
|
|
|
// --- exports
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
CONFIG: CONFIG,
|
|
|
|
triton: triton,
|
2015-09-29 21:45:34 +03:00
|
|
|
safeTriton: safeTriton,
|
2015-09-01 10:31:00 +03:00
|
|
|
ifErr: testcommon.ifErr
|
|
|
|
};
|