forked from googleapis/nodejs-gce-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
103 lines (80 loc) · 2.49 KB
/
test.js
File metadata and controls
103 lines (80 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
var assert = require('assert');
var async = require('async');
var gceImages = require('./index.js')();
describe('gce-images', function () {
var allImagesByOsName = {
deprecated: {},
stable: {}
};
before(function (done) {
// Get counts.
async.forEachOf(
allImagesByOsName,
function (_, key, next) {
gceImages.getAll({ deprecated: key === 'deprecated' }, function (err, images) {
if (err) {
next(err);
return;
}
allImagesByOsName[key] = images;
next();
});
},
done);
});
describe('all', function () {
it('should default to deprecated: false', function (done) {
gceImages.getAll(function (err, images) {
assert.ifError(err);
assert.strictEqual(typeof images, 'object');
Object.keys(images).forEach(function (osName) {
assert.strictEqual(images[osName].length, allImagesByOsName.stable[osName].length);
});
done();
});
});
it('should get all of the images available for a specific OS', function (done) {
var osName = 'ubuntu';
gceImages.getAll(osName, function (err, images) {
assert.ifError(err);
assert(Array.isArray(images));
assert.strictEqual(images.length, allImagesByOsName.stable[osName].length);
done();
});
});
});
describe('latest', function () {
it('should get only the latest image from every OS', function (done) {
gceImages.getLatest(function (err, images) {
assert.ifError(err);
assert.strictEqual(typeof images, 'object');
Object.keys(images).forEach(function (osName) {
assert.strictEqual(images[osName].length, 1);
});
done();
});
});
it('should get the latest image for a specific OS', function (done) {
var osName = 'ubuntu';
gceImages.getLatest(osName, function (err, image) {
assert.ifError(err);
assert.strictEqual(typeof image, 'object');
assert(image.selfLink.indexOf(osName) > -1);
done();
});
});
it('should get the latest image for a specific OS version', function (done) {
var osName = 'ubuntu-1410';
gceImages.getLatest({
osNames: [osName],
deprecated: true
}, function (err, image) {
assert.ifError(err);
assert.strictEqual(typeof image, 'object');
assert(image.selfLink.indexOf(osName) > -1);
done();
});
});
});
});