Allow spaces in volume definitions

Closes: #1247
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-04-07 10:33:45 +01:00
parent ae92ff54b2
commit 0950b66c52
2 changed files with 31 additions and 2 deletions

View File

@ -1012,9 +1012,9 @@ export class Service {
const [bindSource, bindDest, mode] = volume.split(':');
if (!path.isAbsolute(bindSource)) {
// namespace our volumes by appId
let volumeDef = `${appId}_${bindSource}:${bindDest}`;
let volumeDef = `${appId}_${bindSource.trim()}:${bindDest.trim()}`;
if (mode != null) {
volumeDef = `${volumeDef}:${mode}`;
volumeDef = `${volumeDef}:${mode.trim()}`;
}
volumes.push(volumeDef);
} else {

View File

@ -240,6 +240,35 @@ describe('compose/service', () => {
.that.deep.equals(['80/tcp', '100/tcp']);
});
it('should correctly handle spaces in volume definitions', () => {
const service = Service.fromComposeObject(
{
appId: 123,
serviceId: 123,
serviceName: 'test',
volumes: [
'vol1:vol2',
'vol3 :/usr/src/app',
'vol4: /usr/src/app',
'vol5 : vol6',
],
},
{ appName: 'test' } as any,
);
expect(service.config)
.to.have.property('volumes')
.that.deep.equals([
'123_vol1:vol2',
'123_vol3:/usr/src/app',
'123_vol4:/usr/src/app',
'123_vol5:vol6',
'/tmp/balena-supervisor/services/123/test:/tmp/resin',
'/tmp/balena-supervisor/services/123/test:/tmp/balena',
]);
});
describe('Ordered array parameters', () => {
it('Should correctly compare ordered array parameters', () => {
const svc1 = Service.fromComposeObject(