2015-09-02 10:03:17 +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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-18 01:39:43 +02:00
|
|
|
* Copyright 2017 Joyent, Inc.
|
2015-09-02 10:03:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Integration tests for `triton network(s)`
|
|
|
|
*/
|
|
|
|
|
|
|
|
var h = require('./helpers');
|
|
|
|
var test = require('tape');
|
|
|
|
|
|
|
|
var common = require('../../lib/common');
|
|
|
|
|
|
|
|
|
|
|
|
// --- Globals
|
|
|
|
|
|
|
|
var networks;
|
|
|
|
|
|
|
|
|
|
|
|
// --- Tests
|
|
|
|
|
|
|
|
test('triton networks', function (tt) {
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network list -h', function (t) {
|
2015-09-02 10:03:17 +03:00
|
|
|
h.triton('networks -h', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
2016-01-05 07:53:52 +02:00
|
|
|
t.ok(/Usage:\s+triton network list/.test(stdout));
|
2015-09-02 10:03:17 +03:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton help networks', function (t) {
|
|
|
|
h.triton('help networks', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
2016-01-10 02:55:12 +02:00
|
|
|
// JSSTYLED
|
|
|
|
t.ok(/shortcut for "triton network list"/.test(stdout));
|
2015-09-02 10:03:17 +03:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton networks', function (t) {
|
|
|
|
h.triton('networks', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
t.ok(/^SHORTID\b/.test(stdout));
|
|
|
|
t.ok(/\bFABRIC\b/.test(stdout));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network list', function (t) {
|
|
|
|
h.triton('network list', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
t.ok(/^SHORTID\b/.test(stdout));
|
|
|
|
t.ok(/\bFABRIC\b/.test(stdout));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-18 01:39:43 +02:00
|
|
|
tt.test(' triton networks public=false', function (t) {
|
|
|
|
h.triton('networks public=false -H -o public',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var results = stdout.trim().split('\n');
|
|
|
|
results.forEach(function (result) {
|
|
|
|
t.equal(false, common.boolFromString(result, null, 'public'));
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton network list public=false', function (t) {
|
|
|
|
h.triton('network list public=false -H -o public',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var results = stdout.trim().split('\n');
|
|
|
|
results.forEach(function (result) {
|
|
|
|
t.equal(false, common.boolFromString(result, null, 'public'));
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton network list public=true', function (t) {
|
|
|
|
h.triton('network list public=true -H -o public',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var results = stdout.trim().split('\n');
|
|
|
|
results.forEach(function (result) {
|
|
|
|
t.equal(true, common.boolFromString(result, null, 'public'));
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton network list public=bogus', function (t) {
|
|
|
|
h.triton('network list public=bogus', function (err, stdout, stderr) {
|
|
|
|
t.ok(err, err);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-09-02 10:03:17 +03:00
|
|
|
tt.test(' triton networks -l', function (t) {
|
|
|
|
h.triton('networks -l', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
t.ok(/^ID\b/.test(stdout));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.test(' triton networks -j', function (t) {
|
|
|
|
h.triton('networks -j', function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
networks = [];
|
|
|
|
stdout.split('\n').forEach(function (line) {
|
|
|
|
if (!line.trim()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
networks.push(JSON.parse(line));
|
|
|
|
});
|
|
|
|
t.ok(networks.length > 0, 'have at least one network');
|
|
|
|
t.ok(common.isUUID(networks[0].id));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
test('triton network get', function (tt) {
|
2015-09-02 10:03:17 +03:00
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network get -h', function (t) {
|
|
|
|
h.triton('network get -h', function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
t.ok(/Usage:\s+triton network\b/.test(stdout));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network help get', function (t) {
|
|
|
|
h.triton('network help get', function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
2016-01-05 07:53:52 +02:00
|
|
|
t.ok(/Usage:\s+triton network get\b/.test(stdout));
|
2015-09-02 10:03:17 +03:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network get', function (t) {
|
|
|
|
h.triton('network get', function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
t.ok(err);
|
|
|
|
t.ok(/error \(Usage\)/.test(stderr));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network get ID', function (t) {
|
|
|
|
h.triton('network get ' + networks[0].id,
|
|
|
|
function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var network = JSON.parse(stdout);
|
|
|
|
t.equal(network.id, networks[0].id);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network get SHORTID', function (t) {
|
2015-09-02 10:03:17 +03:00
|
|
|
var shortid = networks[0].id.split('-')[0];
|
2016-01-05 07:53:52 +02:00
|
|
|
h.triton('network get ' + shortid, function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var network = JSON.parse(stdout);
|
|
|
|
t.equal(network.id, networks[0].id);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-05 07:53:52 +02:00
|
|
|
tt.test(' triton network get NAME', function (t) {
|
|
|
|
h.triton('network get ' + networks[0].name,
|
|
|
|
function (err, stdout, stderr) {
|
2015-09-02 10:03:17 +03:00
|
|
|
if (h.ifErr(t, err))
|
|
|
|
return t.end();
|
|
|
|
var network = JSON.parse(stdout);
|
|
|
|
t.equal(network.id, networks[0].id);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|