1 | import Docker from 'dockerode'
|
2 | import DockerExecutor from '../src/DockerExecutor'
|
3 | import { fixture } from './test-functions'
|
4 |
|
5 | const docker = new Docker
|
6 | const executor = new DockerExecutor
|
7 |
|
8 | jest.setTimeout(30 * 60 * 1000)
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | test('execute:stdout', async () => {
|
15 |
|
16 | let build = await docker.buildImage({
|
17 | context: fixture('dockerfile-execute-stdout'),
|
18 | src: ['Dockerfile']
|
19 | }, {t: 'dockerfile-execute-stdout'})
|
20 |
|
21 | let built = await docker.modem.followProgress(build, onFinished)
|
22 |
|
23 | async function onFinished () {
|
24 | let output = await executor.execute('dockerfile-execute-stdout', __dirname)
|
25 | expect(output).toEqual('hello')
|
26 | }
|
27 |
|
28 | })
|
29 |
|
30 | test('execute:stderr', async () => {
|
31 |
|
32 | let build = await docker.buildImage({
|
33 | context: fixture('dockerfile-execute-stderr'),
|
34 | src: ['Dockerfile']
|
35 | }, {t: 'dockerfile-execute-stderr'})
|
36 |
|
37 | let built = await docker.modem.followProgress(build, onFinished)
|
38 |
|
39 | async function onFinished () {
|
40 | let outputError = ''
|
41 |
|
42 | const spy = jest.spyOn(console,'error')
|
43 | .mockImplementation((data:string) => {
|
44 | outputError += data
|
45 | })
|
46 |
|
47 | await executor.execute('dockerfile-execute-stderr', __dirname)
|
48 |
|
49 | expect(outputError.trim()).toBe('epicfail')
|
50 |
|
51 | spy.mockRestore()
|
52 | }
|
53 |
|
54 | })
|