Skip to content

Commit 7ec7abe

Browse files
authored
Merge pull request #98 from JoonasVali/interpret-empty-object-to-default-opts
Interpret empty object as default opts and fix tests on windows
2 parents 287161b + e78223e commit 7ec7abe

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/modem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var defaultOpts = function() {
6363
};
6464

6565
var Modem = function(opts) {
66-
if (!opts) {
66+
if (!opts || (Object.keys(opts).length === 0 && opts.constructor === Object)) {
6767
opts = defaultOpts();
6868
}
6969

test/modem_test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
var assert = require('assert');
22
var Modem = require('../lib/modem');
3+
var defaultSocketPath = require('os').type() === 'Windows_NT' ? '//./pipe/docker_engine' : '/var/run/docker.sock';
34

45
describe('Modem', function() {
56
beforeEach(function() {
67
delete process.env.DOCKER_HOST;
78
});
89

9-
it('should default to /var/run/docker.sock', function() {
10+
it('should default to default socket path', function() {
1011
var modem = new Modem();
1112
assert.ok(modem.socketPath);
12-
assert.strictEqual(modem.socketPath, '/var/run/docker.sock');
13+
assert.strictEqual(modem.socketPath, defaultSocketPath);
14+
});
15+
16+
it('should default to default socket path with empty object argument', function() {
17+
var modem = new Modem({});
18+
assert.ok(modem.socketPath);
19+
assert.strictEqual(modem.socketPath, defaultSocketPath);
20+
});
21+
22+
it('should not default to default socket path with non-empty object argument', function () {
23+
var modem = new Modem({a: 'b'});
24+
assert.strictEqual(modem.socketPath, undefined);
1325
});
1426

1527
it('should allow DOCKER_HOST=unix:///path/to/docker.sock', function() {

0 commit comments

Comments
 (0)