clistyle: some more tritonapi tests.

This commit is contained in:
Marsell Kukuljevic 2016-01-11 23:35:43 +11:00
parent b8d7194ee8
commit 09954b3f55
4 changed files with 247 additions and 3 deletions

View File

@ -427,9 +427,6 @@ TritonApi.prototype.getPackage = function getPackage(name, cb) {
format('package with id %s was not found', name));
}
cb(err);
} else if (!pkg.active) {
cb(new errors.TritonError(
format('package %s is not active', name)));
} else {
cb(null, pkg);
}

View File

@ -0,0 +1,81 @@
/*
* 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.
*/
/*
* Integration tests for using instance-related APIs as a module.
*/
var h = require('./helpers');
var test = require('tape');
var common = require('../../lib/common');
// --- Globals
var CLIENT;
var INST;
// --- Tests
test('TritonApi packages', function (tt) {
tt.test(' setup', function (t) {
CLIENT = h.createClient();
t.ok(CLIENT, 'client');
CLIENT.cloudapi.listMachines(function (err, insts) {
if (h.ifErr(t, err))
return t.end();
t.ok(Array.isArray(insts), 'instances');
INST = insts[0];
t.end();
});
});
tt.test(' TritonApi getInstance', function (t) {
if (!INST) {
return t.end();
}
function check(val, valName, next) {
CLIENT.getInstance(val, function (err, inst) {
if (h.ifErr(t, err, 'no err'))
return t.end();
t.deepEqual(inst, INST, valName);
next();
});
}
var shortId = INST.id.split('-')[0];
check(INST.id, 'id', function () {
check(INST.name, 'name', function () {
check(shortId, 'shortId', function () {
t.end();
});
});
});
});
tt.test(' teardown: client', function (t) {
CLIENT.close();
t.end();
});
});

View File

@ -0,0 +1,85 @@
/*
* 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.
*/
/*
* Integration tests for using network-related APIs as a module.
*/
var h = require('./helpers');
var test = require('tape');
var common = require('../../lib/common');
// --- Globals
var CLIENT;
var NET;
// --- Tests
test('TritonApi networks', function (tt) {
tt.test(' setup', function (t) {
CLIENT = h.createClient();
t.ok(CLIENT, 'client');
var opts = {
account: CLIENT.profile.account
};
CLIENT.cloudapi.listNetworks(opts, function (err, nets) {
if (h.ifErr(t, err))
return t.end();
t.ok(Array.isArray(nets), 'networks');
NET = nets[0];
t.end();
});
});
tt.test(' TritonApi getNetwork', function (t) {
if (!NET) {
return t.end();
}
function check(val, valName, next) {
CLIENT.getNetwork(val, function (err, net) {
if (h.ifErr(t, err, 'no err'))
return t.end();
t.deepEqual(net, NET, valName);
next();
});
}
var shortId = NET.id.split('-')[0];
check(NET.id, 'id', function () {
check(NET.name, 'name', function () {
check(shortId, 'shortId', function () {
t.end();
});
});
});
});
tt.test(' teardown: client', function (t) {
CLIENT.close();
t.end();
});
});

View File

@ -0,0 +1,81 @@
/*
* 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.
*/
/*
* Integration tests for using package-related APIs as a module.
*/
var h = require('./helpers');
var test = require('tape');
var common = require('../../lib/common');
// --- Globals
var CLIENT;
var PKG;
// --- Tests
test('TritonApi packages', function (tt) {
tt.test(' setup', function (t) {
CLIENT = h.createClient();
t.ok(CLIENT, 'client');
CLIENT.cloudapi.listPackages(function (err, pkgs) {
if (h.ifErr(t, err))
return t.end();
t.ok(Array.isArray(pkgs), 'packages');
PKG = pkgs[0];
t.end();
});
});
tt.test(' TritonApi getPackage', function (t) {
if (!PKG) {
return t.end();
}
function check(val, valName, next) {
CLIENT.getPackage(val, function (err, pkg) {
if (h.ifErr(t, err, 'no err'))
return t.end();
t.deepEqual(pkg, PKG, valName);
next();
});
}
var shortId = PKG.id.split('-')[0];
check(PKG.id, 'id', function () {
check(PKG.name, 'name', function () {
check(shortId, 'shortId', function () {
t.end();
});
});
});
});
tt.test(' teardown: client', function (t) {
CLIENT.close();
t.end();
});
});