mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-22 03:55:22 +00:00
Convert test/18-compose-network.coffee to javascript
Change-type: patch
This commit is contained in:
parent
d3cf650ac4
commit
98e956831a
@ -94,7 +94,9 @@ export class Network {
|
||||
public static fromComposeObject(
|
||||
name: string,
|
||||
appId: number,
|
||||
network: Partial<ComposeNetworkConfig>,
|
||||
network: Partial<Omit<ComposeNetworkConfig, 'ipam'>> & {
|
||||
ipam?: Partial<ComposeNetworkConfig['ipam']>;
|
||||
},
|
||||
opts: NetworkOptions,
|
||||
): Network {
|
||||
const net = new Network(opts);
|
||||
|
@ -1,104 +0,0 @@
|
||||
{ expect } = require './lib/chai-config'
|
||||
|
||||
{ Network } = require '../src/compose/network'
|
||||
|
||||
describe 'compose/network', ->
|
||||
|
||||
describe 'compose config -> internal config', ->
|
||||
|
||||
it 'should convert a compose configuration to an internal representation', ->
|
||||
|
||||
network = Network.fromComposeObject('test', 123, {
|
||||
'driver': 'bridge',
|
||||
'ipam': {
|
||||
'driver': 'default',
|
||||
'config': [
|
||||
{
|
||||
'subnet': '172.25.0.0/25',
|
||||
'gateway': '172.25.0.1'
|
||||
}
|
||||
]
|
||||
}
|
||||
}, { 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: {}
|
||||
})
|
||||
|
||||
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'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
describe 'internal config -> docker config', ->
|
||||
|
||||
it 'should convert an internal representation to a docker representation', ->
|
||||
|
||||
network = Network.fromComposeObject('test', 123, {
|
||||
'driver': 'bridge',
|
||||
'ipam': {
|
||||
'driver': 'default',
|
||||
'config': [
|
||||
{
|
||||
'subnet': '172.25.0.0/25',
|
||||
'gateway': '172.25.0.1'
|
||||
}
|
||||
]
|
||||
}
|
||||
}, { 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'
|
||||
}
|
||||
})
|
125
test/18-compose-network.js
Normal file
125
test/18-compose-network.js
Normal file
@ -0,0 +1,125 @@
|
||||
import { expect } from './lib/chai-config';
|
||||
import { Network } from '../src/compose/network';
|
||||
|
||||
describe('compose/network', function() {
|
||||
describe('compose config -> internal config', function() {
|
||||
it('should convert a compose configuration to an internal representation', function() {
|
||||
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: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle an incomplete ipam configuration', function() {
|
||||
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', () =>
|
||||
it('should convert an internal representation to a docker representation', function() {
|
||||
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',
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user