2019-06-19 17:23:19 +00:00
|
|
|
{ expect } = require './lib/chai-config'
|
2018-07-25 12:59:59 +00:00
|
|
|
|
|
|
|
{ Network } = require '../src/compose/network'
|
|
|
|
|
2018-10-17 14:34:07 +00:00
|
|
|
describe 'compose/network', ->
|
2018-07-25 12:59:59 +00:00
|
|
|
|
|
|
|
describe 'compose config -> internal config', ->
|
|
|
|
|
|
|
|
it 'should convert a compose configuration to an internal representation', ->
|
|
|
|
|
2019-07-02 08:33:15 +00:00
|
|
|
network = Network.fromComposeObject('test', 123, {
|
2018-11-02 14:15:01 +00:00
|
|
|
'driver': 'bridge',
|
|
|
|
'ipam': {
|
|
|
|
'driver': 'default',
|
|
|
|
'config': [
|
2018-07-25 12:59:59 +00:00
|
|
|
{
|
2018-11-02 14:15:01 +00:00
|
|
|
'subnet': '172.25.0.0/25',
|
|
|
|
'gateway': '172.25.0.1'
|
2018-07-25 12:59:59 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-07-02 08:33:15 +00:00
|
|
|
}, { logger: null, docker: null })
|
2018-07-25 12:59:59 +00:00
|
|
|
|
|
|
|
expect(network.config).to.deep.equal({
|
|
|
|
driver: 'bridge'
|
|
|
|
ipam: {
|
|
|
|
driver: 'default'
|
|
|
|
config: [
|
|
|
|
subnet: '172.25.0.0/25'
|
|
|
|
gateway: '172.25.0.1'
|
|
|
|
]
|
2018-11-02 14:15:01 +00:00
|
|
|
options: {}
|
2018-07-25 12:59:59 +00:00
|
|
|
}
|
|
|
|
enableIPv6: false,
|
|
|
|
internal: false,
|
2018-11-02 14:15:01 +00:00
|
|
|
labels: {}
|
|
|
|
options: {}
|
2018-07-25 12:59:59 +00:00
|
|
|
})
|
|
|
|
|
2019-09-16 09:52:18 +00:00
|
|
|
it 'should handle an incomplete ipam configuration', ->
|
|
|
|
network = Network.fromComposeObject('test', 123, {
|
|
|
|
ipam: {
|
|
|
|
config: [
|
|
|
|
{
|
|
|
|
subnet: '172.25.0.0/25',
|
|
|
|
gateway: '172.25.0.1'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}, { 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'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-07-25 12:59:59 +00:00
|
|
|
describe 'internal config -> docker config', ->
|
|
|
|
|
|
|
|
it 'should convert an internal representation to a docker representation', ->
|
|
|
|
|
2019-07-02 08:33:15 +00:00
|
|
|
network = Network.fromComposeObject('test', 123, {
|
2018-11-02 14:15:01 +00:00
|
|
|
'driver': 'bridge',
|
|
|
|
'ipam': {
|
|
|
|
'driver': 'default',
|
|
|
|
'config': [
|
2018-07-25 12:59:59 +00:00
|
|
|
{
|
2018-11-02 14:15:01 +00:00
|
|
|
'subnet': '172.25.0.0/25',
|
|
|
|
'gateway': '172.25.0.1'
|
2018-07-25 12:59:59 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-07-02 08:33:15 +00:00
|
|
|
}, { logger: null, docker: null })
|
2018-07-25 12:59:59 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
}]
|
2018-11-02 14:15:01 +00:00
|
|
|
Options: {}
|
2018-07-25 12:59:59 +00:00
|
|
|
}
|
|
|
|
EnableIPv6: false,
|
|
|
|
Internal: false,
|
|
|
|
Labels: {
|
2018-10-17 14:34:07 +00:00
|
|
|
'io.balena.supervised': 'true'
|
2018-07-25 12:59:59 +00:00
|
|
|
}
|
2018-10-17 14:34:07 +00:00
|
|
|
})
|