2015-09-29 21:45:52 +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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-02-09 22:23:55 +02:00
|
|
|
* Copyright 2016, Joyent, Inc.
|
2015-09-29 21:45:52 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test 'profiles' and 'profile'
|
|
|
|
*/
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var h = require('./helpers');
|
|
|
|
var test = require('tape');
|
|
|
|
|
|
|
|
var PROFILE_FILE = path.join(__dirname, 'test-profile.json');
|
|
|
|
var PROFILE_DATA = JSON.parse(fs.readFileSync(PROFILE_FILE, 'utf8'));
|
|
|
|
|
|
|
|
var opts = {
|
2015-10-07 22:19:26 +03:00
|
|
|
skip: !h.CONFIG.allowWriteActions
|
2015-09-29 21:45:52 +03:00
|
|
|
};
|
|
|
|
|
2016-03-28 21:39:41 +03:00
|
|
|
|
2015-09-29 21:45:52 +03:00
|
|
|
// --- Tests
|
|
|
|
|
|
|
|
if (opts.skip) {
|
2015-10-07 22:19:26 +03:00
|
|
|
console.error('** skipping %s tests', __filename);
|
|
|
|
console.error('** set "allowWriteActions" in test config to enable');
|
2015-09-29 21:45:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
test('triton profiles (read only)', function (tt) {
|
2015-12-31 01:25:12 +02:00
|
|
|
tt.test(' triton profile get env', function (t) {
|
|
|
|
h.safeTriton(t, {json: true, args: ['profile', 'get', '-j', 'env']},
|
2016-02-09 22:23:55 +02:00
|
|
|
function (err, p) {
|
2015-09-29 21:45:52 +03:00
|
|
|
|
2015-10-07 09:09:52 +03:00
|
|
|
t.equal(p.account, h.CONFIG.profile.account,
|
2015-09-29 21:45:52 +03:00
|
|
|
'env account correct');
|
2015-10-07 09:09:52 +03:00
|
|
|
t.equal(p.keyId, h.CONFIG.profile.keyId,
|
2015-09-29 21:45:52 +03:00
|
|
|
'env keyId correct');
|
2015-10-07 09:09:52 +03:00
|
|
|
t.equal(p.url, h.CONFIG.profile.url,
|
2015-09-29 21:45:52 +03:00
|
|
|
'env url correct');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('triton profiles (read/write)', opts, function (tt) {
|
2015-10-07 09:09:52 +03:00
|
|
|
tt.test(' triton profile create', function (t) {
|
2016-03-28 21:39:41 +03:00
|
|
|
/*
|
|
|
|
* We need to skip the Docker setup with '--no-docker' because we are
|
|
|
|
* using a bogus keyId and CloudAPI url. The Docker setup requires real
|
|
|
|
* values because it makes requests to CloudAPI (e.g. ListServices to
|
|
|
|
* find the Docker endpoint).
|
|
|
|
*/
|
|
|
|
h.safeTriton(t, ['profile', 'create', '--no-docker',
|
|
|
|
'-f', PROFILE_FILE],
|
2016-02-09 22:23:55 +02:00
|
|
|
function (err, stdout) {
|
2015-09-29 21:45:52 +03:00
|
|
|
t.ok(stdout.match(/^Saved profile/), 'stdout correct');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-07 09:09:52 +03:00
|
|
|
tt.test(' triton profile get', function (t) {
|
2015-09-29 21:45:52 +03:00
|
|
|
h.safeTriton(t,
|
2015-12-31 01:25:12 +02:00
|
|
|
{json: true, args: ['profile', 'get', '-j', PROFILE_DATA.name]},
|
2016-02-09 22:23:55 +02:00
|
|
|
function (err, p) {
|
2015-09-29 21:45:52 +03:00
|
|
|
|
|
|
|
t.deepEqual(p, PROFILE_DATA, 'profile matched');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-07 09:09:52 +03:00
|
|
|
tt.test(' triton profile delete', function (t) {
|
2015-12-31 01:25:12 +02:00
|
|
|
h.safeTriton(t, ['profile', 'delete', '-f', PROFILE_DATA.name],
|
2016-02-09 22:23:55 +02:00
|
|
|
function (err, stdout) {
|
2015-09-29 21:45:52 +03:00
|
|
|
|
|
|
|
t.ok(stdout.match(/^Deleted profile/), 'stdout correct');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.end();
|
|
|
|
});
|