Skip to content

Commit

Permalink
Adjust to docker beta release
Browse files Browse the repository at this point in the history
See https://beta.docker.com/docs

Now logic is changed - if docker-machine is present give their address
if not just return localhost
  • Loading branch information
markelog committed May 7, 2016
1 parent 7af86f7 commit d19d49e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 76 deletions.
22 changes: 7 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { execSync as exec } from 'child_process';

function ip(type = 'default') {
const isLinux = ip.platform === 'linux';

if (!ip.present()) {
if (isLinux) {
return 'localhost';
}
if (ip.present()) {
return ip.exec(`docker-machine ip ${type}`, {
encoding: 'utf8',

return null;
// By default parent stderr is used, which is bad
stdio: []
}).trim();
}

return ip.exec(`docker-machine ip ${type}`, {
encoding: 'utf8',

// By default parent stderr is used, which is bad
stdio: []
}).trim();
return 'localhost';
}

ip.present = () => {

try {
ip.exec('docker-machine version && echo $?', {
encoding: 'utf8',
Expand All @@ -36,6 +29,5 @@ ip.present = () => {
};

ip.exec = exec;
ip.platform = process.platform;

export default ip;
61 changes: 0 additions & 61 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,67 +62,6 @@ describe('docker-ip', () => {
});
});

describe('if "docker machine" is not present', () => {
beforeEach(() => {
sinon.stub(ip, 'present', () => false);
});

afterEach(() => {
ip.present.restore();
});

it('should get `default` ip without arguments', () => {
expect(ip()).to.equal(null);
expect(ip.exec).to.not.be.called;
});

it('should get `dev` ip', () => {
expect(ip('dev')).to.equal(null);
expect(ip.exec).to.not.be.called;
});
});
});

describe('linux', () => {
let old = ip.platform;
beforeEach(() => {
sinon.stub(ip, 'exec', () => 'test');
ip.platform = 'linux';
});

afterEach(() => {
ip.exec.restore();
ip.platform = old;
});

describe('if "docker machine" is present', () => {
beforeEach(() => {
sinon.stub(ip, 'present', () => true);
});

afterEach(() => {
ip.present.restore();
});

it('should get `default` ip without arguments', () => {
ip();
expect(ip.exec.firstCall.args[0]).to.equal('docker-machine ip default');
expect(ip.exec.firstCall.args[1]).to.deep.equal({
encoding: 'utf8',
stdio: []
});
});

it('should get `dev` ip', () => {
ip('dev');
expect(ip.exec.firstCall.args[0]).to.equal('docker-machine ip dev');
expect(ip.exec.firstCall.args[1]).to.deep.equal({
encoding: 'utf8',
stdio: []
});
});
});

describe('if "docker machine" is not present', () => {
beforeEach(() => {
sinon.stub(ip, 'present', () => false);
Expand Down

0 comments on commit d19d49e

Please sign in to comment.