forked from devcontainers/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerComposeUtils.test.ts
More file actions
99 lines (89 loc) · 2.51 KB
/
Copy pathdockerComposeUtils.test.ts
File metadata and controls
99 lines (89 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { assert } from 'chai';
import * as yaml from 'js-yaml';
import * as path from 'path';
import { getBuildInfoForService } from '../spec-node/dockerCompose';
const testComposeFile = path.join('somepath', 'docker-compose.yml');
function loadYamlAndGetBuildInfoForService(input: string) {
const yamlInput = yaml.load(input);
return getBuildInfoForService(yamlInput, path, [testComposeFile]);
}
describe('docker-compose - getBuildInfoForService', () => {
it('Parses fully specified info', () => {
const input = `
image: my-image
build:
context: context-path
dockerfile: my-dockerfile
target: a-target
args:
arg1: value1
`;
const info = loadYamlAndGetBuildInfoForService(input);
assert.deepEqual(info, {
image: 'my-image',
build: {
context: 'context-path',
dockerfilePath: 'my-dockerfile',
target: 'a-target',
args: {
arg1: 'value1',
},
}
});
});
it('Parses image-only info', () => {
const input = `
image: my-image
`;
const info = loadYamlAndGetBuildInfoForService(input);
assert.deepEqual(info, {
image: 'my-image'
});
});
it('Parses string build info', () => {
const input = `
image: my-image
build: ./a-path
`;
const info = loadYamlAndGetBuildInfoForService(input);
assert.deepEqual(info, {
image: 'my-image',
build: {
context: './a-path',
dockerfilePath: 'Dockerfile'
}
});
});
it('Supplies default dockerFilePath when not set', () => {
const input = `
build:
context: ./a-path
`;
const info = loadYamlAndGetBuildInfoForService(input);
assert.deepEqual(info, {
image: undefined,
build: {
context: './a-path',
dockerfilePath: 'Dockerfile',
target: undefined,
args: undefined,
}
});
});
it('Supplies default context when not set', () => {
const input = `
build:
dockerfile: my-dockerfile
`;
const info = loadYamlAndGetBuildInfoForService(input);
assert.deepEqual(info, {
image: undefined,
build: {
context: path.dirname(testComposeFile),
dockerfilePath: 'my-dockerfile',
target: undefined,
args: undefined,
}
});
});
});