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/unit/parseVolumeSize.test.js
Trent Mick e0b6c7e0bc joyent/node-triton#232 commit 8438f44 broke parseVolumeSize unit tests
Reviewed by: Julien Gilli <julien.gilli@joyent.com>
Approved by: Julien Gilli <julien.gilli@joyent.com>
2017-09-26 15:58:45 -07:00

89 lines
2.3 KiB
JavaScript

/*
* 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) 2017, Joyent, Inc.
*/
/*
* Unit tests for `parseVolumeSize` used by `triton volume ...`.
*/
var assert = require('assert-plus');
var test = require('tape');
var parseVolumeSize = require('../../lib/volumes').parseVolumeSize;
test('parseVolumeSize', function (tt) {
tt.test('parsing invalid sizes', function (t) {
var invalidVolumeSizes = [
'foo',
'0',
'-42',
'-42m',
'-42g',
'',
'42Gasdf',
'42gasdf',
'42asdf',
'asdf42G',
'asdf42g',
'asdf42',
'042g',
'042G',
'042',
0,
42,
-42,
42.1,
-42.1,
undefined,
null,
{}
];
invalidVolumeSizes.forEach(function parse(invalidVolumeSize) {
var parseErr;
try {
parseVolumeSize(invalidVolumeSize);
} catch (err) {
parseErr = err;
}
t.ok(parseErr, 'parsing invalid volume size: ' + invalidVolumeSize +
' should throw');
});
t.end();
});
tt.test('parsing valid sizes', function (t) {
var validVolumeSizes = [
{input: '42G', expectedOutput: 42 * 1024}
];
validVolumeSizes.forEach(function parse(validVolumeSize) {
var parseErr;
var volSizeInMebibytes;
try {
volSizeInMebibytes = parseVolumeSize(validVolumeSize.input);
} catch (err) {
parseErr = err;
}
t.ifErr(parseErr, 'parsing valid volume size: ' +
validVolumeSize.input + ' should not throw');
t.equal(validVolumeSize.expectedOutput, volSizeInMebibytes,
'parsed volume size for "' + validVolumeSize.input + '" ' +
'should equal to ' + validVolumeSize.expectedOutput +
' mebibytes');
});
t.end();
});
});