Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docker-mock

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docker-mock - npm Package Compare versions

Comparing version 5.1.0 to 5.1.1

.istanbul.yml

7

CHANGELOG.md
## Change Log
### upcoming (2015/11/01 01:57 +00:00)
- [#51](https://github.com/Runnable/docker-mock/pull/51) Update Deps; Mocha + Chai (@bkendall)
- [#50](https://github.com/Runnable/docker-mock/pull/50) travis badge for master (@bkendall)
### v5.1.0 (2015/10/21 23:35 +00:00)
- [#49](https://github.com/Runnable/docker-mock/pull/49) control exit code via kill signals (@tjmehta)
### v5.0.2 (2015/10/14 21:26 +00:00)

@@ -4,0 +11,0 @@ - [#48](https://github.com/Runnable/docker-mock/pull/48) fix: move callback-count to dependencies (@bkendall)

9

lib/index.js

@@ -181,6 +181,7 @@ 'use strict';

app.post('/images/create', function (req, res, next) {
images
.create(req, res)
.then(function () { res.end(); })
.catch(next);
// this function is NOT promisified
images.create(req, res, function (err) {
if (err) { next(err); }
res.end();
});
});

@@ -187,0 +188,0 @@

@@ -36,3 +36,6 @@ 'use strict';

this.findOneById(id)
]);
]).catch(function (errs) {
// if we get all errors, throw just the first one
throw errs[0];
});
};

@@ -39,0 +42,0 @@

@@ -59,8 +59,7 @@ 'use strict';

delete opts.Labels;
var capitalizedBody = mapKeys(opts, utils.capitalize);
if (capitalizedBody.Name) {
capitalizedBody.Name = '/' + capitalizedBody.Name;
var capitalizedOpts = mapKeys(opts, utils.capitalize);
if (capitalizedOpts.Name) {
capitalizedOpts.Name = '/' + capitalizedOpts.Name;
}
assign(data, capitalizedBody);
assign(this, data, opts);
assign(this, data, capitalizedOpts);
}

@@ -67,0 +66,0 @@ util.inherits(Container, EventEmitter);

@@ -212,8 +212,9 @@ 'use strict';

function resError (code, message) {
reject(new Error('Server Error - ' + message, {
var error = new Error('Server Error - ' + message, {
code: code,
message: message
}));
});
reject(error);
}
});
};
{
"name": "docker-mock",
"version": "5.1.0",
"version": "5.1.1",
"description": "Mock for Docker",

@@ -11,7 +11,13 @@ "main": "lib/index.js",

"changelog": "github-changes -o Runnable -r docker-mock -a --only-pulls --use-commit-body --order-semver",
"coverage": "lab --reporter lcov --output lcov.info",
"unit": "lab --threshold 100 test/models test/utils",
"test": "lab --threshold 98",
"lint": "eslint ."
"coverage-check": "istanbul check-coverage && echo 'Coverage check successful!'",
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- $npm_package_options_mocha test/models test/utils && npm run coverage-check",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"functional": "NODE_ENV=test mocha $npm_package_options_mocha test",
"lint": "eslint .",
"test": "npm run lint && npm run unit && npm run functional",
"unit": "NODE_ENV=test mocha $npm_package_options_mocha test/models test/utils"
},
"options": {
"mocha": "--require resources/mocha-bootstrap --timeout 5000 --recursive --reporter spec --bail"
},
"keywords": [

@@ -30,3 +36,3 @@ "docker",

"101": "^1.0.0",
"bluebird": "^2.10.0",
"bluebird": "^3.0.2",
"body-parser": "^1.10.1",

@@ -39,3 +45,3 @@ "callback-count": "^0.2.0",

"minimist": "^1.1.0",
"object-loops": "^0.2.0",
"object-loops": "^0.3.1",
"tar": "^2.1.0",

@@ -47,11 +53,13 @@ "tar-stream": "^1.2.1"

"async": "^1.2.1",
"code": "^1.3.0",
"chai": "^3.4.0",
"chai-as-promised": "^5.1.0",
"concat-stream": "^1.4.7",
"cucumber": "^0.5.2",
"coveralls": "^2.11.4",
"dockerode": "^2.2.2",
"eslint": "^1.2.1",
"github-changes": "^1.0.0",
"lab": "^5.2.1",
"istanbul": "^0.4.0",
"mocha": "^2.3.3",
"request": "^2.51.0"
}
}
# docker-mock
[![Build Status](https://img.shields.io/travis/Runnable/docker-mock.svg?style=flat-square)](https://travis-ci.org/Runnable/docker-mock)
[![Build Status](https://img.shields.io/travis/Runnable/docker-mock/master.svg?style=flat-square)](https://travis-ci.org/Runnable/docker-mock)
[![Dependency Status](https://img.shields.io/david/Runnable/docker-mock.svg?style=flat-square)](https://david-dm.org/Runnable/docker-mock)

@@ -5,0 +5,0 @@ [![devDependency Status](https://img.shields.io/david/dev/Runnable/docker-mock.svg?style=flat-square)](https://david-dm.org/Runnable/docker-mock#info=devDependencies)

'use strict';
var chai = require('chai');
var assert = chai.assert;
var async = require('async');

@@ -10,12 +13,2 @@ var checkClean = require('./fixtures').checkClean;

var Lab = require('lab');
var lab = exports.lab = Lab.script();
var after = lab.after;
var afterEach = lab.afterEach;
var before = lab.before;
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
var docker = require('dockerode')({

@@ -57,6 +50,6 @@ host: 'http://localhost',

// this should be capitalized and used
expect(containerData.Name).to.equal('/' + createData.name);
expect(containerData.Env).to.be.an.array();
expect(containerData.Env).to.have.length(1);
expect(containerData.Env[0]).to.equal(createData.Env[0]);
assert.propertyVal(containerData, 'Name', '/' + createData.name);
assert.isArray(containerData.Env);
assert.lengthOf(containerData.Env, 1);
assert.equal(containerData.Env[0], createData.Env[0]);
docker.getContainer(createData.name).remove(done);

@@ -68,6 +61,7 @@ });

if (err) { return done(err); }
expect(containers.length).to.equal(0);
assert.lengthOf(containers, 0);
done();
});
});
describe('labels', function () {

@@ -92,11 +86,16 @@ var container;

});
it('should save Labels on create and respond with Labels on inspect',
function (done) {
container.inspect(function (err, data) {
if (err) { return done(err); }
expect(data.Config.Labels).to.deep.contain(Labels);
done();
});
});
function (done) {
container.inspect(function (err, data) {
if (err) { return done(err); }
Object.keys(Labels).forEach(function (l) {
assert.equal(data.Config.Labels[l], Labels[l]);
});
done();
});
}
);
});
describe('interactions', function () {

@@ -118,4 +117,4 @@ var container;

if (err) { return done(err); }
expect(containers.length).to.equal(1);
expect(containers[0].Id).to.equal(container.id);
assert.lengthOf(containers, 1);
assert.equal(containers[0].Id, container.id);
done();

@@ -127,3 +126,3 @@ });

if (err) { return done(err); }
expect(data.Id).to.equal(container.id);
assert.equal(data.Id, container.id);
done();

@@ -160,3 +159,3 @@ });

if (err) { return cb(err); }
expect(data.Id).to.contain(imageData.Id);
assert.include(data.Id, imageData.Id);
cb(null, image);

@@ -175,6 +174,4 @@ });

data = JSON.parse(data);
expect(data).to.deep.contain({
status: 'start',
id: container.id
});
assert.equal(data.status, 'start');
assert.equal(data.id, container.id);
count.next();

@@ -188,4 +185,4 @@ });

data = data[1]; // get the inspect data
expect(data.State.Running).to.be.true();
expect(data.State.Pid).to.be.a.number();
assert.equal(data.State.Running, true);
assert.isNumber(data.State.Pid);
count.next();

@@ -203,3 +200,3 @@ });

logs.pipe(concat(function (logBuffer) {
expect(logBuffer.toString()).to.equal('Just a bunch of text');
assert.equal(logBuffer.toString(), 'Just a bunch of text');
count.next();

@@ -225,3 +222,3 @@ }));

if (err) { return done(err); }
expect(data).to.deep.equal(originalInspect);
assert.deepEqual(data, originalInspect);
done();

@@ -232,17 +229,12 @@ });

it('should be able to stop it', function (done) {
var count = createCount(4, function (err) {
var count = createCount(2, function (err) {
dockerMock.events.stream.removeAllListeners('data');
done(err);
});
// these events should happen in this order
var expectedEvents = [ 'start', 'die', 'stop' ];
dockerMock.events.stream.on('data', function (data) {
data = JSON.parse(data);
var expectedEvent = expectedEvents.shift();
expect(data).to.deep.contain({
status: expectedEvent,
id: container.id
});
count.next();
});
assertEvents(
container,
dockerMock.events.stream,
[ 'start', 'die', 'stop' ],
count.next
);
async.series([

@@ -255,4 +247,4 @@ container.start.bind(container),

data = data[2];
expect(data.State.Running).to.be.false();
expect(data.State.Pid).to.equal(0);
assert.equal(data.State.Running, false);
assert.equal(data.State.Pid, 0);
count.next();

@@ -269,4 +261,4 @@ });

data = data[2];
expect(data.State.Running).to.be.false();
expect(data.State.Pid).to.equal(0);
assert.equal(data.State.Running, false);
assert.equal(data.State.Pid, 0);
done();

@@ -282,7 +274,7 @@ });

container.stop(function (stopErr) {
expect(stopErr.statusCode).to.equal(304);
assert.propertyVal(stopErr, 'statusCode', 304);
container.inspect(function (err, data) {
if (err) { return done(err); }
expect(data.State.Running).to.be.false();
expect(data.State.Pid).to.equal(0);
assert.deepPropertyVal(data, 'State.Running', false);
assert.deepPropertyVal(data, 'State.Pid', 0);
done();

@@ -294,17 +286,12 @@ });

it('should be able to kill it', function (done) {
var count = createCount(4, function (err) {
var count = createCount(2, function (err) {
dockerMock.events.stream.removeAllListeners('data');
done(err);
});
// these events should happen in this order
var expectedEvents = [ 'start', 'die', 'kill' ];
dockerMock.events.stream.on('data', function (data) {
data = JSON.parse(data);
var expectedEvent = expectedEvents.shift();
expect(data).to.deep.contain({
status: expectedEvent,
id: container.id
});
count.next();
});
assertEvents(
container,
dockerMock.events.stream,
[ 'start', 'die', 'kill' ],
count.next
);
async.series([

@@ -317,4 +304,4 @@ container.start.bind(container),

if (err) { return count.next(err); }
expect(data.State.Running).to.be.false();
expect(data.State.ExitCode).to.equal(1);
assert.deepPropertyVal(data, 'State.Running', false);
assert.deepPropertyVal(data, 'State.ExitCode', 1);
count.next();

@@ -325,17 +312,12 @@ });

it('should be able to kill it w/ a signal', function (done) {
var count = createCount(4, function (err) {
var count = createCount(2, function (err) {
dockerMock.events.stream.removeAllListeners('data');
done(err);
});
// these events should happen in this order
var expectedEvents = [ 'start', 'die', 'kill' ];
dockerMock.events.stream.on('data', function (data) {
data = JSON.parse(data);
var expectedEvent = expectedEvents.shift();
expect(data).to.deep.contain({
status: expectedEvent,
id: container.id
});
count.next();
});
assertEvents(
container,
dockerMock.events.stream,
[ 'start', 'die', 'kill' ],
count.next
);
async.series([

@@ -348,5 +330,5 @@ container.start.bind(container),

if (err) { return count.next(err); }
expect(data.State.Running).to.be.false();
assert.deepPropertyVal(data, 'State.Running', false);
// 0 anything other than SIGKILL
expect(data.State.ExitCode).to.equal(0);
assert.deepPropertyVal(data, 'State.ExitCode', 0);
count.next();

@@ -357,17 +339,12 @@ });

it('should be able to restart it', function (done) {
var count = createCount(5, function (err) {
var count = createCount(2, function (err) {
dockerMock.events.stream.removeAllListeners('data');
done(err);
});
// these events should happen in this order
var expectedEvents = [ 'start', 'die', 'start', 'restart' ];
dockerMock.events.stream.on('data', function (data) {
data = JSON.parse(data);
var expectedEvent = expectedEvents.shift();
expect(data).to.deep.contain({
status: expectedEvent,
id: container.id
});
count.next();
});
assertEvents(
container,
dockerMock.events.stream,
[ 'start', 'die', 'start', 'restart' ],
count.next
);
async.series([

@@ -381,3 +358,3 @@ container.start.bind(container),

// FIXME: these test are broken. this does not return true
expect(data.State.Running).to.be.true();
assert.deepPropertyVal(data, 'State.Running', true);
count.next();

@@ -389,1 +366,12 @@ });

});
function assertEvents (container, eventStream, expectedEvents, callback) {
var count = createCount(expectedEvents.length, callback);
eventStream.on('data', function (data) {
data = JSON.parse(data);
var expectedEvent = expectedEvents.shift();
assert.propertyVal(data, 'status', expectedEvent);
assert.propertyVal(data, 'id', container.id);
count.next();
});
}
'use strict';
var chai = require('chai');
var assert = chai.assert;
var checkClean = require('./fixtures').checkClean;

@@ -7,10 +10,2 @@ var dockerMock = require('../../lib/index');

var Lab = require('lab');
var lab = exports.lab = Lab.script();
var after = lab.after;
var before = lab.before;
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var it = lab.it;
var docker = require('dockerode')({

@@ -31,3 +26,7 @@ host: 'http://localhost',

it('should return info data', function (done) {
docker.info(done);
docker.info(function (err, data) {
if (err) { return done(err); }
assert.propertyVal(data, 'Mock', true);
done();
});
});

@@ -38,3 +37,7 @@ });

it('should return version data', function (done) {
docker.version(done);
docker.version(function (err, data) {
if (err) { return done(err); }
assert.ok(data.Os);
done();
});
});

@@ -46,3 +49,3 @@ });

request.get('http://localhost:5354/_nope', function (err, res) {
if (err && res.statusCode === 501) {
if (err) {
done(err);

@@ -49,0 +52,0 @@ } else if (res.statusCode !== 501) {

'use strict';
var JSONStream = require('JSONStream');
var chai = require('chai');
var assert = chai.assert;
var async = require('async');

@@ -8,12 +10,4 @@ var checkClean = require('./fixtures').checkClean;

var dockerMock = require('../../lib/index');
var JSONStream = require('JSONStream');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var after = lab.after;
var before = lab.before;
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
var docker = require('dockerode')({

@@ -39,6 +33,6 @@ host: 'http://localhost',

eventStream.pipe(JSONStream.parse()).on('data', function (json) {
expect(json.status).to.be.a.string();
expect(json.id).to.be.a.string();
expect(json.from).to.be.a.string();
expect(json.time).to.be.a.number();
assert.isString(json.status);
assert.isString(json.id);
assert.isString(json.from);
assert.isNumber(json.time);
count.next();

@@ -57,6 +51,6 @@ });

eventStream.pipe(JSONStream.parse()).on('data', function (json) {
expect(json.status).to.be.a.string();
expect(json.id).to.be.a.string();
expect(json.from).to.be.a.string();
expect(json.time).to.be.a.number();
assert.isString(json.status);
assert.isString(json.id);
assert.isString(json.from);
assert.isNumber(json.time);
count.next();

@@ -84,6 +78,6 @@ });

var json = JSON.parse(data.toString());
expect(json.status).to.be.a.string();
expect(json.id).to.be.a.string();
expect(json.from).to.be.a.string();
expect(json.time).to.be.a.number();
assert.isString(json.status);
assert.isString(json.id);
assert.isString(json.from);
assert.isNumber(json.time);
if (i++ === 9) {

@@ -124,7 +118,7 @@ // this destroys the _socket_

var expectedEvent = expectedEvents.shift();
expect(json.status).to.be.a.string();
expect(json.status).to.equal(expectedEvent);
expect(json.id).to.be.a.string();
expect(json.from).to.be.a.string();
expect(json.time).to.be.a.number();
assert.isString(json.status);
assert.equal(json.status, expectedEvent);
assert.isString(json.id);
assert.isString(json.from);
assert.isNumber(json.time);
if (expectedEvents.length === 0) {

@@ -160,6 +154,6 @@ eventStream.destroy();

var json = JSON.parse(data.toString());
expect(json.status).to.be.a.string();
expect(json.id).to.be.a.string();
expect(json.from).to.be.a.string();
expect(json.time).to.be.a.number();
assert.isString(json.status);
assert.isString(json.id);
assert.isString(json.from);
assert.isNumber(json.time);
if (i++ >= 5) {

@@ -166,0 +160,0 @@ // this destroys the _socket_

'use strict';
var assert = require('chai').assert;
var async = require('async');
var expect = require('code').expect;
var isFunction = require('101/is-function');

@@ -23,3 +24,3 @@ var noop = require('101/noop');

function (images, _cb) {
expect(images.length).to.equal(0);
assert.lengthOf(images, 0);
_cb();

@@ -33,3 +34,3 @@ }

function (containers, _cb) {
expect(containers.length).to.equal(0);
assert.lengthOf(containers, 0);
_cb();

@@ -43,5 +44,5 @@ }

function (data, _cb) {
expect(data.Containers).to.equal(0);
expect(data.Images).to.equal(0);
expect(data.Mock).to.be.true();
assert.equal(data.Containers, 0);
assert.equal(data.Images, 0);
assert.equal(data.Mock, true);
_cb();

@@ -48,0 +49,0 @@ }

'use strict';
var chai = require('chai');
var assert = chai.assert;
var dockerMock = require('../../lib/index');

@@ -8,11 +11,2 @@ var fs = require('fs');

var Lab = require('lab');
var lab = exports.lab = Lab.script();
var after = lab.after;
var before = lab.before;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
var docker = require('dockerode')({

@@ -41,3 +35,3 @@ protocol: 'https',

if (err) { return done(err); }
expect(data).to.deep.equal({
assert.deepEqual(data, {
Containers: 0,

@@ -44,0 +38,0 @@ Images: 0,

'use strict';
var chai = require('chai');
var assert = chai.assert;
var async = require('async');

@@ -16,12 +19,2 @@ var checkClean = require('./fixtures').checkClean;

var Lab = require('lab');
var lab = exports.lab = Lab.script();
var after = lab.after;
var afterEach = lab.afterEach;
var before = lab.before;
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
var docker = require('dockerode')({

@@ -72,6 +65,5 @@ host: 'http://localhost',

if (err) { return done(err); }
expect(images).to.have.length(2);
expect(images[0].Created).to.equal(100);
expect(images[1].Created)
.to.be.about(Math.floor(Date.now() / 1000), 10);
assert.lengthOf(images, 2);
assert.equal(images[0].Created, 100);
assert.closeTo(images[1].Created, Math.floor(Date.now() / 1000), 10);
done();

@@ -165,3 +157,3 @@ });

if (err) { return done(err); }
expect(images).to.have.length(0);
assert.lengthOf(images, 0);
done();

@@ -232,8 +224,7 @@ });

if (err) { return done(err); }
expect(images).to.have.length(2);
expect(images[0].RepoTags).to.have.length(1);
expect(images[0].RepoTags[0]).to.equal('testImage:latest');
expect(images[0].Created).to.be.a.number();
expect(images[0].Created)
.to.be.about(Math.floor(Date.now() / 1000), 10);
assert.lengthOf(images, 2);
assert.lengthOf(images[0].RepoTags, 1);
assert.equal(images[0].RepoTags[0], 'testImage:latest');
assert.isNumber(images[0].Created);
assert.closeTo(images[0].Created, Math.floor(Date.now() / 1000), 10);
done();

@@ -244,3 +235,3 @@ });

docker.getImage('fake').get(function (err) {
expect(err.statusCode).to.equal(404);
assert.equal(err.statusCode, 404);
done();

@@ -270,3 +261,3 @@ });

// the tarball has 3 images and no repotag: three layers expected
expect(images.length - numImages).to.equal(3);
assert.equal(images.length - numImages, 3);
cb();

@@ -289,3 +280,3 @@ });

if (err) { return done(err); }
expect(history).to.have.length(1);
assert.lengthOf(history, 1);
done();

@@ -298,3 +289,3 @@ });

if (!err) { return done(new Error('expected an error')); }
expect(err.statusCode).to.equal(404);
assert.equal(err.statusCode, 404);
done();

@@ -306,3 +297,3 @@ });

.push({}, handleStream(function (err) {
expect(err.statusCode).to.equal(404);
assert.equal(err.statusCode, 404);
done();

@@ -334,3 +325,3 @@ }));

.push({}, handleStream(function (err) {
expect(err.statusCode).to.equal(404);
assert.equal(err.statusCode, 404);
done();

@@ -337,0 +328,0 @@ }));

'use strict';
var chai = require('chai');
var assert = chai.assert;
var BaseStore = require('../../lib/models/base-store');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var before = lab.before;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('Base Store', function () {
var store;
before(function (done) {
before(function () {
store = new BaseStore();
done();
});
describe('NotModifiedError', function () {
it('should expose NotModifiedError', function (done) {
expect(BaseStore.NotModifiedError).to.exist();
expect(function () { new BaseStore.NotModifiedError(); })
.not.to.throw();
done();
it('should expose NotModifiedError', function () {
assert.ok(BaseStore.NotModifiedError);
assert.doesNotThrow(function () { new BaseStore.NotModifiedError(); });
assert.ok(new BaseStore.NotModifiedError());
});
});
describe('NotFoundError', function () {
it('should expose NotFoundError', function () {
assert.ok(BaseStore.NotFoundError);
assert.doesNotThrow(function () { new BaseStore.NotFoundError(); });
assert.ok(new BaseStore.NotFoundError());
});
});
describe('findOneById', function () {
before(function (done) {
before(function () {
store._store[4] = { hello: 'world' };
done();
});
it('should find something in it\'s store by id', function (done) {
store.findOneById(4)
it('should find something in it\'s store by id', function () {
return assert.isFulfilled(store.findOneById(4))
.then(function (o) {
expect(o).to.deep.equal({ hello: 'world' });
})
.finally(done);
assert.deepEqual(o, { hello: 'world' });
});
});
it('should return NotFoundError if cannot find object', function (done) {
store.findOneById(5)
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.an.instanceof(BaseStore.NotFoundError);
})
.finally(done);
it('should return NotFoundError if cannot find object', function () {
return assert.isRejected(store.findOneById(5), BaseStore.NotFoundError);
});
});
});
'use strict';
var chai = require('chai');
var assert = chai.assert;
var assign = require('101/assign');
var ContainerStore = require('../../lib/models/container-store');
var createCount = require('callback-count');
var EventEmitter = require('events').EventEmitter;
var ContainerStore = require('../../lib/models/container-store');
var NotFoundError = require('../../lib/models/base-store').NotFoundError;
var assign = require('101/assign');
var createCount = require('callback-count');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('Container Store', function () {
var containers;
var container;
beforeEach(function (done) {
beforeEach(function () {
container = new EventEmitter();

@@ -29,21 +25,15 @@ assign(container, {

containers._store[4] = container;
done();
});
describe('findOneByName', function () {
it('should find something by name', function (done) {
containers.findOneByName('test-container')
.then(function (o) { expect(o).to.deep.equal(container); })
.finally(done);
it('should find something by name', function () {
return assert.isFulfilled(containers.findOneByName('test-container'))
.then(function (o) { assert.deepEqual(o, container); });
});
it('should return NotFoundError if cannot find container', function (done) {
containers.findOneByName('nope-container')
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.an.instanceof(NotFoundError);
})
.finally(done);
it('should return NotFoundError if cannot find container', function () {
return assert.isRejected(
containers.findOneByName('nope-container'),
NotFoundError
);
});

@@ -53,12 +43,13 @@ });

describe('findOneByIdOrName', function () {
it('should find one by name', function (done) {
containers.findOneByIdOrName('test-container')
.then(function (o) { expect(o).to.deep.equal(container); })
.finally(done);
it('should find one by name', function () {
return assert.isFulfilled(containers.findOneByIdOrName('test-container'))
.then(function (o) { assert.deepEqual(o, container); });
});
it('should find one by id', function (done) {
containers.findOneByIdOrName(4)
.then(function (o) { expect(o).to.deep.equal(container); })
.finally(done);
it('should find one by id', function () {
return assert.isFulfilled(containers.findOneByIdOrName(4))
.then(function (o) { assert.deepEqual(o, container); });
});
it('should return a not found error if both fail', function () {
return assert.isRejected(containers.findOneByIdOrName(-1), NotFoundError);
});
});

@@ -69,11 +60,10 @@

var expectedEvents = ['destroy'];
var count = createCount(expectedEvents.length + 1, done);
var count = createCount(expectedEvents.length, done);
containers.on('event', function (type, c) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
expect(c).to.deep.equal(container);
assert.equal(type, expectedEvent);
assert.deepEqual(c, container);
count.next();
});
containers.deleteById(4)
.finally(count.next);
return assert.isFulfilled(containers.deleteById(4));
});

@@ -83,9 +73,9 @@ });

describe('listContainers', function () {
it('should list containers', function (done) {
containers.listContainers()
it('should list containers', function () {
return assert.isFulfilled(containers.listContainers())
.then(function (containers) {
expect(containers).to.have.length(1);
expect(containers[0]).to.deep.contain({ Id: 4, Image: 'ubuntu' });
})
.finally(done);
assert.lengthOf(containers, 1);
assert.propertyVal(containers[0], 'Id', 4);
assert.propertyVal(containers[0], 'Image', 'ubuntu');
});
});

@@ -95,4 +85,4 @@ });

describe('createContainer', function () {
it('should create a container', function (done) {
containers.createContainer({})
it('should create a container', function () {
return assert.isFulfilled(containers.createContainer({}))
.then(function () {

@@ -102,21 +92,19 @@ return containers.listContainers();

.then(function (containers) {
expect(containers).to.have.length(2);
})
.finally(done);
assert.lengthOf(containers, 2);
});
});
it('should register for container events and emit create', function (done) {
var expectedEvents = [ 'create', 'start' ];
var count = createCount(expectedEvents.length + 1, done);
var count = createCount(expectedEvents.length, done);
containers.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
assert.equal(type, expectedEvent);
count.next();
});
containers.createContainer({})
return assert.isFulfilled(containers.createContainer({}))
.then(function (container) {
return container.start();
})
.finally(count.next);
});
});
});
});
'use strict';
var chai = require('chai');
var assert = chai.assert;
var Container = require('../../lib/models/container');
var createCount = require('callback-count');
var NotModifiedError = require('../../lib/models/base-store').NotModifiedError;
var createCount = require('callback-count');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('Container', function () {
var container;
beforeEach(function (done) {
beforeEach(function () {
container = new Container();
done();
});
describe('constructor options', function () {
it('should respect various options passed in', function (done) {
it('should respect various options passed in', function () {
var opts = {

@@ -28,6 +23,10 @@ Labels: { hello: 'world' },

var c = new Container(opts);
expect(c.Config.Labels).to.deep.equal({ hello: 'world' });
expect(c.Image).to.equal('ubuntu');
done();
assert.deepProperty(c, 'Config.Labels');
assert.deepEqual(c.Config.Labels, { hello: 'world' });
assert.propertyVal(c, 'Image', 'ubuntu');
});
it('should prepend Name with a slash', function () {
var c = new Container({ Name: 'foo' });
assert.propertyVal(c, 'Name', '/foo');
});
});

@@ -37,26 +36,12 @@

it('should start and emit the correct events', function (done) {
var expectedEvents = ['start'];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
container.start()
assertEvents(container, ['start'], done);
return assert.isFulfilled(container.start())
.then(function (c) {
expect(c.State.Running).to.be.true();
expect(c.NetworkSettings.Ports).to.exist();
})
.finally(count.next);
assert.deepPropertyVal(c, 'State.Running', true);
assert.deepProperty(c, 'NetworkSettings.Ports');
});
});
it('should throw NotModifiedError if already started', function (done) {
it('should throw NotModifiedError if already started', function () {
container.State.Running = true;
container.start()
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.instanceof(NotModifiedError);
})
.finally(done);
return assert.isRejected(container.start(), NotModifiedError);
});

@@ -67,24 +52,10 @@ });

it('should start and emit the correct events', function (done) {
var expectedEvents = [ 'start', 'restart' ];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, [ 'start', 'restart' ], done);
// start(true) => restart
container.start(true)
.finally(count.next);
return assert.isFulfilled(container.start(true));
});
it('should stop and emit the correct events', function (done) {
var expectedEvents = ['die'];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, ['die'], done);
// start(true) => restart
container.stop('restart')
.finally(count.next);
return assert.isFulfilled(container.stop('restart'));
});

@@ -95,22 +66,8 @@ });

it('should stop and emit the correct events', function (done) {
var expectedEvents = [ 'die', 'stop' ];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, [ 'die', 'stop' ], done);
container.State.Running = true;
container.stop()
.finally(count.next);
return assert.isFulfilled(container.stop());
});
it('should throw NotModifiedError if already stopped', function (done) {
container.stop()
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.instanceof(NotModifiedError);
})
.finally(done);
it('should throw NotModifiedError if already stopped', function () {
return assert.isRejected(container.stop(), NotModifiedError);
});

@@ -122,51 +79,40 @@ });

function (done) {
var expectedEvents = [ 'die', 'kill' ];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, [ 'die', 'kill' ], done);
container.State.Running = true;
container.stop('kill')
return assert.isFulfilled(container.stop('kill'))
.then(function (c) {
expect(c.State.Running).to.be.false();
expect(c.State.ExitCode).to.equal(0);
})
.finally(count.next);
});
assert.equal(c.State.Running, false);
assert.deepPropertyVal(c, 'State.ExitCode', 0);
});
}
);
it('should stop via kill and emit the correct events', function (done) {
var expectedEvents = [ 'die', 'kill' ];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, [ 'die', 'kill' ], done);
container.State.Running = true;
container.stop('kill', 'SIGKILL')
return assert.isFulfilled(container.stop('kill', 'SIGKILL'))
.then(function (c) {
expect(c.State.Running).to.be.false();
expect(c.State.ExitCode).to.equal(1);
})
.finally(count.next);
assert.deepPropertyVal(c, 'State.Running', false);
assert.deepPropertyVal(c, 'State.ExitCode', 1);
});
});
it('should stop via kill w/ signal and emit the correct events',
function (done) {
var expectedEvents = [ 'die', 'kill' ];
var count = createCount(expectedEvents.length + 1, done);
container.on('event', function (type) {
var expectedEvent = expectedEvents.shift();
expect(type).to.equal(expectedEvent);
count.next();
});
assertEvents(container, [ 'die', 'kill' ], done);
container.State.Running = true;
container.stop('kill', 'SIGINT')
return assert.isFulfilled(container.stop('kill', 'SIGINT'))
.then(function (c) {
expect(c.State.Running).to.be.false();
expect(c.State.ExitCode).to.equal(0);
})
.finally(count.next);
assert.deepPropertyVal(c, 'State.Running', false);
assert.deepPropertyVal(c, 'State.ExitCode', 0);
});
});
});
});
function assertEvents (container, events, callback) {
var count = createCount(events.length, callback);
container.on('event', function (type) {
var expectedEvent = events.shift();
assert.equal(type, expectedEvent);
count.next();
});
}
'use strict';
var chai = require('chai');
var assert = chai.assert;
var assign = require('101/assign');
var ImageStore = require('../../lib/models/image-store');
var NotFoundError = require('../../lib/models/base-store').NotFoundError;
var assign = require('101/assign');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var beforeEach = lab.beforeEach;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('Image Store', function () {
var images;
var image;
beforeEach(function (done) {
beforeEach(function () {
image = assign({}, { Id: '4' });

@@ -22,44 +18,27 @@ images = new ImageStore();

images._tags['ubuntu:latest'] = '4';
done();
images._imageHistory['4'] = [];
});
describe('findOneByName', function () {
it('should find an image by name', function (done) {
images.findOneByName('ubuntu')
.then(function (o) { expect(o).to.deep.equal(image); })
.finally(done);
it('should find an image by name', function () {
return assert.isFulfilled(images.findOneByName('ubuntu'))
.then(function (o) { assert.deepEqual(o, image); });
});
it('should find an image by name with tag', function (done) {
images.findOneByName('ubuntu:latest')
.then(function (o) { expect(o).to.deep.equal(image); })
.finally(done);
it('should find an image by name with tag', function () {
return assert.isFulfilled(images.findOneByName('ubuntu:latest'))
.then(function (o) { assert.deepEqual(o, image); });
});
it('should find an image by id', function (done) {
images.findOneByName('4')
.then(function (o) { expect(o).to.deep.equal(image); })
.finally(done);
it('should find an image by id', function () {
return assert.isFulfilled(images.findOneByName('4'))
.then(function (o) { assert.deepEqual(o, image); });
});
it('should return NotFoundError if cannot find image', function (done) {
images.findOneByName('node')
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.an.instanceof(NotFoundError);
})
.finally(done);
it('should return NotFoundError if cannot find image', function () {
return assert.isRejected(images.findOneByName('node'), NotFoundError);
});
it('should return NotFoundError if image was lost', function (done) {
it('should return NotFoundError if image was lost', function () {
// this is a really weird state, but we'll test for it
// the tag still exists, but the image does not
delete images._store['4'];
images.findOneByName('ubuntu')
.then(function () {
throw new Error('it should have returned NotFoundError');
})
.catch(function (err) {
expect(err).to.be.an.instanceof(NotFoundError);
})
.finally(done);
return assert.isRejected(images.findOneByName('ubuntu'), NotFoundError);
});

@@ -69,7 +48,6 @@ });

describe('deleteByName', function () {
it('should delete an image', function (done) {
images.deleteByName('ubuntu')
it('should delete an image', function () {
return assert.isFulfilled(images.deleteByName('ubuntu'))
.then(function () { return images.listImages(); })
.then(function (images) { expect(images).to.have.length(0); })
.finally(done);
.then(function (images) { assert.lengthOf(images, 0); });
});

@@ -79,15 +57,87 @@ });

describe('listImages', function () {
it('should list images', function (done) {
it('should list images', function () {
images._tags.foo = 'bar';
images.listImages()
.then(function (images) { expect(images).to.have.length(1); })
.finally(done);
return assert.isFulfilled(images.listImages())
.then(function (images) { assert.lengthOf(images, 1); });
});
it('should list images with container config', function (done) {
it('should list images with container config', function () {
image.container_config = {}; // eslint-disable-line camelcase
images.listImages()
.then(function (images) { expect(images).to.have.length(1); })
.finally(done);
return assert.isFulfilled(images.listImages())
.then(function (images) { assert.lengthOf(images, 1); });
});
});
describe('commitComtainer', function () {
it('should save a container', function () {
var mockContainer = { _id: 8 };
var query = { repo: 'test-repo' };
return assert.isFulfilled(images.commitContainer(mockContainer, query))
.then(function (image) {
assert.ok(image.Id);
return images.listImages();
})
.then(function (images) {
assert.lengthOf(images, 2);
assert.equal(images[1].RepoTags[0], 'test-repo:latest');
});
});
it('should save a container with custom tag', function () {
var mockContainer = { _id: 8 };
var query = {
repo: 'test-repo',
tag: 'not-latest'
};
return assert.isFulfilled(images.commitContainer(mockContainer, query))
.then(function (image) {
assert.ok(image.Id);
return images.listImages();
})
.then(function (images) {
assert.lengthOf(images, 2);
assert.equal(images[1].RepoTags[0], 'test-repo:not-latest');
});
});
});
describe('loadImage', function () {
it('should create an image in the store', function () {
var mockImage = {
Id: '536ed6640d827ed0ef5e0e0f582e8d8c60eb9099c767b362e4430d0a6c42f691',
Created: undefined,
RepoTags: ['test-repo:not-latest']
};
return assert.isFulfilled(images.loadImage(mockImage))
.then(function () {
return images.listImages();
})
.then(function (images) {
assert.lengthOf(images, 2);
assert.equal(images[1].Id, mockImage.Id);
});
});
it('should create an image in the store without tags', function () {
var mockImage = {
Id: '536ed6640d827ed0ef5e0e0f582e8d8c60eb9099c767b362e4430d0a6c42f691',
Created: undefined,
RepoTags: []
};
return assert.isFulfilled(images.loadImage(mockImage))
.then(function () {
return images.listImages();
})
.then(function (images) {
assert.lengthOf(images, 2);
assert.equal(images[1].Id, mockImage.Id);
});
});
});
describe('getHistory', function () {
it('should return image history', function () {
return assert.isFulfilled(images.getHistory('4'))
.then(function (history) {
assert.ok(history);
});
});
});
});
'use strict';
var chai = require('chai');
var assert = chai.assert;
var Image = require('../../lib/models/image');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('Image', function () {
it('should exist', function (done) {
expect(function () { new Image({}); }).to.not.throw();
done();
it('should exist', function () {
assert.doesNotThrow(function () { new Image({}); });
assert.ok(new Image({}));
});
});
'use strict';
var chai = require('chai');
var assert = chai.assert;
var utils = require('../../lib/utils');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
describe('utils', function () {
describe('randomId', function () {
it('should always return a 32 bit string in hex', function (done) {
it('should always return a 32 bit string in hex', function () {
// just check 10, for kicks

@@ -18,6 +15,5 @@ var seen = [];

var id = utils.randomId();
expect(seen.indexOf(id)).to.equal(-1);
assert.notInclude(seen, id);
seen.push(id);
}
done();
});

@@ -27,3 +23,3 @@ });

describe('newPid', function () {
it('should always return a new integer pid', function (done) {
it('should always return a new integer pid', function () {
// just check 10, for kicks

@@ -33,6 +29,5 @@ var seen = [];

var id = utils.newPid();
expect(seen.indexOf(id)).to.equal(-1);
assert.notInclude(seen, id);
seen.push(id);
}
done();
});

@@ -42,3 +37,3 @@ });

describe('newPort', function () {
it('should always return a new integer port', function (done) {
it('should always return a new integer port', function () {
// just check 10, for kicks

@@ -48,6 +43,5 @@ var seen = [];

var id = utils.newPort();
expect(seen.indexOf(id)).to.equal(-1);
assert.notInclude(seen, id);
seen.push(id);
}
done();
});

@@ -57,16 +51,14 @@ });

describe('capitalize', function () {
it('should capitalize strings', function (done) {
expect(utils.capitalize('foo')).to.equal('Foo');
expect(utils.capitalize('Bar')).to.equal('Bar');
expect(utils.capitalize('BAR')).to.equal('BAR');
done();
it('should capitalize strings', function () {
assert.equal(utils.capitalize('foo'), 'Foo');
assert.equal(utils.capitalize('Bar'), 'Bar');
assert.equal(utils.capitalize('BAR'), 'BAR');
});
it('should do nothing to not a string', function (done) {
it('should do nothing to not a string', function () {
var obj = {};
expect(utils.capitalize(obj)).to.equal(obj);
expect(utils.capitalize([])).to.deep.equal([]);
expect(utils.capitalize(3)).to.deep.equal(3);
done();
assert.deepEqual(utils.capitalize(obj), obj);
assert.deepEqual(utils.capitalize([]), []);
assert.deepEqual(utils.capitalize(3), 3);
});
});
});
'use strict';
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var chai = require('chai');
var assert = chai.assert;
var describe = lab.describe;
var expect = require('code').expect;
var it = lab.it;
var createCount = require('callback-count');

@@ -14,16 +11,16 @@

describe('string-stream', function () {
it('should not allow passing it a string', function (done) {
expect(function () { new StringStream({}); })
.to.throw(Error, 'first argument must be a string');
done();
it('should not allow passing it a string', function () {
assert.throws(
function () { new StringStream({}); },
Error,
'first argument must be a string'
);
});
it('should accept passing additional ops', function (done) {
it('should accept passing additional ops', function () {
var ss = new StringStream('', { key: true });
expect(ss).to.exist();
done();
assert.ok(ss);
});
it('should work without passing opts', function (done) {
it('should work without passing opts', function () {
var ss = new StringStream('');
expect(ss).to.exist();
done();
assert.ok(ss);
});

@@ -34,4 +31,4 @@ it('should output data', function (done) {

ss.on('data', function (d) {
expect(d).to.be.an.instanceof(Buffer);
expect(d.toString()).to.equal('Hello, World!');
assert.instanceOf(d, Buffer);
assert.equal(d.toString(), 'Hello, World!');
count.next();

@@ -38,0 +35,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc