UNPKG

3.02 kBPlain TextView Raw
1import Docker from 'dockerode'
2
3import DockerBuilder from '../src/DockerBuilder'
4import { fixture } from './test-functions'
5
6// This is intended to be the only test file where we do any actual Docker image builds
7// Increase timeout (in milliseconds) to allow for Docker builds
8jest.setTimeout(30 * 60 * 1000)
9
10/**
11 * When applied to a Dockerfile with a # dockter comment
12 * should produce a staged build
13 */
14test('build:py-requests-dockter', async () => {
15 const builder = new DockerBuilder()
16 const docker = new Docker()
17
18 // Remove any existing images
19 try {
20 await docker.getImage('py-requests-dockter:latest').remove()
21 } catch (error) {
22 if (!error.message.includes('No such image')) throw error
23 }
24
25 // Build it
26 await builder.build(fixture('py-requests-dockter'), 'py-requests-dockter')
27
28 // Get info for expectations
29 const latest = docker.getImage('py-requests-dockter:latest')
30 const history = await latest.history()
31 const latestInfo = await latest.inspect()
32 const system = docker.getImage('py-requests-dockter:system')
33 const systemInfo = await system.inspect()
34
35 expect(history[0].Comment).toEqual('Updated application layer')
36 expect(history[0].Size).toBeGreaterThan(0)
37 // TODO : add more expectations!
38})
39
40/**
41 * When applied to a Dockerfile *without* a # dockter comment
42 * should act just like Docker build
43 */
44test('build:py-requests-no-dockter', async () => {
45 const builder = new DockerBuilder()
46 const docker = new Docker()
47
48 // Remove any existing images
49 try {
50 await docker.getImage('py-requests-no-dockter:latest').remove()
51 } catch (error) {
52 if (!error.message.includes('No such image')) throw error
53 }
54
55 // Build it
56 await builder.build(fixture('py-requests-no-dockter'), 'py-requests-no-dockter')
57
58 // Get info for expectations
59 const latest = docker.getImage('py-requests-no-dockter:latest')
60 const history = await latest.history()
61 const latestInfo = await latest.inspect()
62 const system = docker.getImage('py-requests-no-dockter:system')
63 const systemInfo = await system.inspect()
64
65 expect(history[0].Comment).toEqual('No updates requested')
66 expect(history[0].Size).toEqual(0)
67 // TODO : add more expectations!
68})
69
70/**
71 * Tests of build failures
72 *
73 * Currently skipped because we are not handling messages right now
74 */
75test.skip('build:py-requests-no-dockter', async () => {
76 const builder = new DockerBuilder()
77 let node
78
79 // Unknown directive (aka instruction)
80 node = await builder.build('FOO ubuntu\n')
81 //expect(node.messages[0].line).toEqual(1)
82 //expect(node.messages[0].message).toEqual('unknown instruction: FOO ')
83
84 // Unknown base image
85 node = await builder.build('FROM foobuntoo\n')
86 //expect(node.messages[0].message).toEqual('pull access denied for foobuntoo, repository does not exist or may require \'docker login\'')
87
88 // Bad RUN command
89 node = await builder.build('FROM ubuntu\nRUN foo')
90 //expect(node.messages[0].message).toEqual("The command '/bin/sh -c foo' returned a non-zero code: 127")
91})