2018-03-06 00:04:36 +02: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 2018 Joyent, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Integration tests for using NIC-related APIs as a module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var h = require('./helpers');
|
|
|
|
var test = require('tape');
|
|
|
|
|
|
|
|
|
|
|
|
// --- Globals
|
|
|
|
|
|
|
|
var CLIENT;
|
|
|
|
var INST;
|
|
|
|
var NIC;
|
|
|
|
|
|
|
|
|
|
|
|
// --- Tests
|
|
|
|
|
2018-06-05 07:32:58 +03:00
|
|
|
test('TritonApi nics', function (tt) {
|
2018-03-06 00:04:36 +02:00
|
|
|
tt.test(' setup', function (t) {
|
2018-06-05 07:32:58 +03:00
|
|
|
h.createClient(function onCreate(err, client_) {
|
2018-03-06 00:04:36 +02:00
|
|
|
t.error(err);
|
|
|
|
CLIENT = client_;
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
tt.test(' setup: inst', function (t) {
|
2018-06-05 07:32:58 +03:00
|
|
|
CLIENT.cloudapi.listMachines({}, function onList(err, vms) {
|
|
|
|
if (vms.length === 0) {
|
|
|
|
t.end();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 00:04:36 +02:00
|
|
|
|
|
|
|
t.ok(Array.isArray(vms), 'vms array');
|
|
|
|
INST = vms[0];
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
tt.test(' TritonApi listNics', function (t) {
|
2018-06-05 07:32:58 +03:00
|
|
|
if (!INST) {
|
|
|
|
t.end();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 00:04:36 +02:00
|
|
|
|
|
|
|
function check(val, valName, next) {
|
2018-06-05 07:32:58 +03:00
|
|
|
CLIENT.listNics({id: val}, function onList(err, nics) {
|
|
|
|
if (h.ifErr(t, err, 'no err ' + valName)) {
|
|
|
|
t.end();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 00:04:36 +02:00
|
|
|
|
|
|
|
t.ok(Array.isArray(nics), 'nics array');
|
|
|
|
NIC = nics[0];
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var shortId = INST.id.split('-')[0];
|
|
|
|
|
2018-06-05 07:32:58 +03:00
|
|
|
check(INST.id, 'id', function doId() {
|
|
|
|
check(INST.name, 'name', function doName() {
|
|
|
|
check(shortId, 'shortId', function doShort() {
|
2018-03-06 00:04:36 +02:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
tt.test(' TritonApi getNic', function (t) {
|
2018-06-05 07:32:58 +03:00
|
|
|
if (!NIC) {
|
|
|
|
t.end();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 00:04:36 +02:00
|
|
|
|
|
|
|
function check(inst, mac, instValName, next) {
|
2018-06-05 07:32:58 +03:00
|
|
|
CLIENT.getNic({id: inst, mac: mac}, function onGet(err, nic) {
|
|
|
|
if (h.ifErr(t, err, 'no err for ' + instValName)) {
|
|
|
|
t.end();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 00:04:36 +02:00
|
|
|
|
|
|
|
t.deepEqual(nic, NIC, instValName);
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var shortId = INST.id.split('-')[0];
|
|
|
|
|
2018-06-05 07:32:58 +03:00
|
|
|
check(INST.id, NIC.mac, 'id', function doId() {
|
|
|
|
check(INST.name, NIC.mac, 'name', function doName() {
|
|
|
|
check(shortId, NIC.mac, 'shortId', function doShort() {
|
2018-03-06 00:04:36 +02:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
tt.test(' teardown: client', function (t) {
|
|
|
|
CLIENT.close();
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|