This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/test/integration/api-images.test.js

100 lines
2.6 KiB
JavaScript
Raw Normal View History

/*
* 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 image-related APIs as a module.
*/
var h = require('./helpers');
var test = require('tape');
var common = require('../../lib/common');
// --- Globals
// --- Tests
test('TritonApi images', function (tt) {
var client;
tt.test(' setup: client', function (t) {
client = h.createClient();
t.ok(client, 'client');
t.end();
});
var testOpts = {};
var img;
tt.test(' TritonApi listImages', function (t) {
client.listImages(function (err, images) {
if (h.ifErr(t, err))
return t.end();
t.ok(images, 'images');
t.ok(Array.isArray(images), 'images');
if (images.length) {
img = images[0];
t.ok(img, 'img');
t.ok(common.isUUID(img.id), 'img.id is a UUID');
t.ok(img.name, 'img.name');
t.ok(img.version, 'img.version');
} else {
testOpts.skip = true;
}
t.end();
});
});
tt.test(' TritonApi getImage by uuid', testOpts, function (t) {
client.getImage(img.id, function (err, image) {
if (h.ifErr(t, err))
return t.end();
t.equal(image.id, img.id);
t.end();
});
});
tt.test(' TritonApi getImage by name', testOpts, function (t) {
client.getImage(img.name, function (err, image) {
if (h.ifErr(t, err))
return t.end();
t.equal(image.name, img.name); // might not be the same ID
t.end();
});
});
tt.test(' TritonApi getImage by name (opts)', testOpts, function (t) {
client.getImage({name: img.name}, function (err, image) {
if (h.ifErr(t, err))
return t.end();
t.equal(image.name, img.name); // might not be the same ID
t.end();
});
});
tt.test(' TritonApi getImage by shortId', testOpts, function (t) {
var shortId = img.id.split('-')[0];
client.getImage(shortId, function (err, image) {
if (h.ifErr(t, err))
return t.end();
t.equal(image.id, img.id);
t.end();
});
});
tt.test(' teardown: client', function (t) {
client.close();
t.end();
});
});