From 09954b3f55ccdd5da229a2ace170b065f18299bd Mon Sep 17 00:00:00 2001 From: Marsell Kukuljevic Date: Mon, 11 Jan 2016 23:35:43 +1100 Subject: [PATCH] clistyle: some more tritonapi tests. --- lib/tritonapi.js | 3 - test/integration/api-instances.test.js | 81 ++++++++++++++++++++++++ test/integration/api-networks.test.js | 85 ++++++++++++++++++++++++++ test/integration/api-packages.test.js | 81 ++++++++++++++++++++++++ 4 files changed, 247 insertions(+), 3 deletions(-) create mode 100644 test/integration/api-instances.test.js create mode 100644 test/integration/api-networks.test.js create mode 100644 test/integration/api-packages.test.js diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 85fc972..a0a3c2c 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -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); } diff --git a/test/integration/api-instances.test.js b/test/integration/api-instances.test.js new file mode 100644 index 0000000..64b19d8 --- /dev/null +++ b/test/integration/api-instances.test.js @@ -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(); + }); +}); diff --git a/test/integration/api-networks.test.js b/test/integration/api-networks.test.js new file mode 100644 index 0000000..e6d31bf --- /dev/null +++ b/test/integration/api-networks.test.js @@ -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(); + }); +}); diff --git a/test/integration/api-packages.test.js b/test/integration/api-packages.test.js new file mode 100644 index 0000000..053711e --- /dev/null +++ b/test/integration/api-packages.test.js @@ -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(); + }); +});