This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest-container-builds.test.js
76 lines (63 loc) · 2.68 KB
/
manifest-container-builds.test.js
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
import dockerParseImage from 'docker-parse-image';
import manifestContainerBuilds from '../src/manifest-container-builds';
describe('`manifestContainerBuilds(manifest)`', () => {
const projectId = 'projectId';
const manifest = 'manifest';
const tag = 'tag';
const image = `gcr.io/${projectId}/image:${tag}`;
function mockGetContainers(image) {
return jest.fn().mockReturnValue([{name: 'container', image}]);
}
function mockGetBuilds() {
return jest.fn().mockReturnValue([{container: 'container'}]);
}
test('ignores containers with unsupported images', () => {
const unsupportedImages = [
'busybox',
'gcr.io/some/image',
`gcr.io/${projectId}/image`,
`gcr.io/${projectId}/image:latest`
]
unsupportedImages.forEach(image => {
const getContainers = mockGetContainers(image);
const getBuilds = mockGetBuilds();
const fn = manifestContainerBuilds({getContainers, getBuilds});
expect(fn(projectId, manifest)).toEqual([]);
});
});
test('ignores containers with empty build annotiations', () => {
const getContainers = mockGetContainers(image);
const getBuilds = jest.fn().mockReturnValue([]);
const fn = manifestContainerBuilds({getContainers, getBuilds});
expect(fn(projectId, manifest)).toEqual([]);
});
test('ignores containers without build annotiation', () => {
const getContainers = mockGetContainers(image);
const getBuilds = jest.fn().mockReturnValue(null);
const fn = manifestContainerBuilds({getContainers, getBuilds});
expect(fn(projectId, manifest)).toEqual([]);
});
test('handles image tagged with a tag', () => {
const image = `gcr.io/${projectId}/image:${tag}`;
const getContainers = mockGetContainers(image);
const getBuilds = mockGetBuilds();
const fn = manifestContainerBuilds({getContainers, getBuilds});
expect(fn(projectId, manifest)).toEqual([{
tagName: tag,
image: dockerParseImage(image),
build: getBuilds()[0],
}]);
});
test('handles images tagged with a commit', () => {
const commitSha = 'c485b392c587652b74623d3694a7888c3b5ce259';
const image = `gcr.io/${projectId}/image:${commitSha}`;
const getContainers = mockGetContainers(image);
const getBuilds = mockGetBuilds();
const fn = manifestContainerBuilds({getContainers, getBuilds});
expect(fn(projectId, manifest)).toEqual([{
commitSha,
image: dockerParseImage(image),
build: getBuilds()[0],
}]);
});
});