diff --git a/lib/modem.js b/lib/modem.js index 9062eb7..63a4b9b 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -60,7 +60,7 @@ var defaultOpts = function () { else { opts.pathPrefix = '/'; } - + opts.host = host.hostname; if (process.env.DOCKER_CERT_PATH) { @@ -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); } diff --git a/test/modem_test.js b/test/modem_test.js index d12e5a4..961c438 100644 --- a/test/modem_test.js +++ b/test/modem_test.js @@ -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';