navy
Version:
Quick and powerful development environments using Docker and Docker Compose
50 lines (47 loc) • 2.23 kB
JavaScript
;
var _chai = require("chai");
var _serviceHost = require("../service-host");
/* eslint-env mocha */
describe('service-host', function () {
describe('getNIPSubdomain', function () {
it('should return an nip.io domain with the correct IP address', async function () {
(0, _chai.expect)(await (0, _serviceHost.getNIPSubdomain)('192.168.1.10')).to.equal('192.168.1.10.nip.io');
});
it('should fallback to localhost when a hostname is passed instead of an IP address', async function () {
process.env.NAVY_EXTERNAL_IP = 'somehostname';
(0, _chai.expect)(await (0, _serviceHost.getNIPSubdomain)('somehostname')).to.equal('127.0.0.1.nip.io');
});
});
describe('createHostForService', function () {
it('should return the correct host for a service', async function () {
(0, _chai.expect)(await (0, _serviceHost.createHostForService)('someservice', 'mynavy', '127.0.0.1')).to.equal('someservice.mynavy.127.0.0.1.nip.io');
(0, _chai.expect)(await (0, _serviceHost.createHostForService)('someservice', 'mynavy', '192.168.1.10')).to.equal('someservice.mynavy.192.168.1.10.nip.io');
});
});
describe('createUrlForService', function () {
it('should return the correct url for a service', async function () {
(0, _chai.expect)(await (0, _serviceHost.createUrlForService)('someservice', 'mynavy', '192.168.99.100')).to.equal('http://someservice.mynavy.192.168.99.100.nip.io');
});
});
describe('getUrlFromService', function () {
it('should extract the host from service ENV config', function () {
const service = {
raw: {
Config: {
Env: ['VIRTUAL_HOST=myservice.coolnavy.127.0.0.1.nip.io']
}
}
};
(0, _chai.expect)((0, _serviceHost.getUrlFromService)(service)).to.equal('http://myservice.coolnavy.127.0.0.1.nip.io');
});
it('should return null when the service object is not valid', function () {
const service = {
raw: {
Config: {}
}
};
(0, _chai.expect)((0, _serviceHost.getUrlFromService)(service)).to.equal(null);
(0, _chai.expect)((0, _serviceHost.getUrlFromService)(undefined)).to.equal(null);
});
});
});