2020-03-31 15:47:29 +00:00
|
|
|
import { expect } from './lib/chai-config';
|
|
|
|
import { Network } from '../src/compose/network';
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
describe('compose/network', function () {
|
|
|
|
describe('compose config -> internal config', function () {
|
|
|
|
it('should convert a compose configuration to an internal representation', function () {
|
2020-03-31 15:47:29 +00:00
|
|
|
const network = Network.fromComposeObject(
|
|
|
|
'test',
|
|
|
|
123,
|
|
|
|
{
|
|
|
|
driver: 'bridge',
|
|
|
|
ipam: {
|
|
|
|
driver: 'default',
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// @ts-ignore ignore passing nulls instead of actual objects
|
|
|
|
{ logger: null, docker: null },
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(network.config).to.deep.equal({
|
|
|
|
driver: 'bridge',
|
|
|
|
ipam: {
|
|
|
|
driver: 'default',
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
enableIPv6: false,
|
|
|
|
internal: false,
|
|
|
|
labels: {},
|
|
|
|
options: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
it('should handle an incomplete ipam configuration', function () {
|
2020-03-31 15:47:29 +00:00
|
|
|
const network = Network.fromComposeObject(
|
|
|
|
'test',
|
|
|
|
123,
|
|
|
|
{
|
|
|
|
ipam: {
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// @ts-ignore ignore passing nulls instead of actual objects
|
|
|
|
{ logger: null, docker: null },
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(network.config).to.deep.equal({
|
|
|
|
driver: 'bridge',
|
|
|
|
enableIPv6: false,
|
|
|
|
internal: false,
|
|
|
|
labels: {},
|
|
|
|
options: {},
|
|
|
|
ipam: {
|
|
|
|
driver: 'default',
|
|
|
|
options: {},
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('internal config -> docker config', () =>
|
2020-05-15 11:01:51 +00:00
|
|
|
it('should convert an internal representation to a docker representation', function () {
|
2020-03-31 15:47:29 +00:00
|
|
|
const network = Network.fromComposeObject(
|
|
|
|
'test',
|
|
|
|
123,
|
|
|
|
{
|
|
|
|
driver: 'bridge',
|
|
|
|
ipam: {
|
|
|
|
driver: 'default',
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// @ts-ignore ignore passing nulls instead of actual objects
|
|
|
|
{ logger: null, docker: null },
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(network.toDockerConfig()).to.deep.equal({
|
|
|
|
Name: '123_test',
|
|
|
|
Driver: 'bridge',
|
|
|
|
CheckDuplicate: true,
|
|
|
|
IPAM: {
|
|
|
|
Driver: 'default',
|
|
|
|
Config: [
|
|
|
|
{
|
|
|
|
Subnet: '172.25.0.0/25',
|
|
|
|
Gateway: '172.25.0.1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
Options: {},
|
|
|
|
},
|
|
|
|
EnableIPv6: false,
|
|
|
|
Internal: false,
|
|
|
|
Labels: {
|
|
|
|
'io.balena.supervised': 'true',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|