Skip to content

Commit

Permalink
socketPath cache
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Oct 10, 2023
1 parent 077e545 commit a48f231
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/modem.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var defaultOpts = function () {
else {
opts.pathPrefix = '/';
}

opts.host = host.hostname;

if (process.env.DOCKER_CERT_PATH) {
Expand Down Expand Up @@ -248,10 +248,13 @@ Modem.prototype.dial = function (options, callback) {

Modem.prototype.getSocketPath = function () {
if (!this.socketPath) return;
if (this.socketPathCache) return Promise.resolve(this.socketPathCache);

var socketPathValue = typeof this.socketPath === 'function'
? this.socketPath() : this.socketPath;

this.socketPathCache = socketPathValue;

return Promise.resolve(socketPathValue);
}

Expand Down
20 changes: 20 additions & 0 deletions test/modem_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ describe('Modem', function () {
});
});

it('should use custom socketPath function once', function () {
process.env.DOCKER_HOST = 'unix://';

var count = 0;

var modem = new Modem();
modem.socketPath = function() {
assert(++count === 1);
return 'testpath';
}
modem.getSocketPath().then((socketPath) => {
assert.ok(socketPath);
assert.ok('testpath');
});
return modem.getSocketPath().then((socketPath) => {
assert.ok(socketPath);
assert.ok('testpath');
});
});

it('should interpret DOCKER_HOST=tcp://N.N.N.N:2376 as https', function () {
process.env.DOCKER_HOST = 'tcp://192.168.59.103:2376';

Expand Down

0 comments on commit a48f231

Please sign in to comment.