Skip to content
Permalink
88dd91b7a5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
47 lines (40 sloc) 1.24 KB
import Docker from 'dockerode'
import {ContainerService} from '../src/container-service'
import {ImageService} from '../src/image-service'
describe('ContainerService', () => {
const docker = new Docker()
let container: any
beforeAll(async () => {
/* We use alpine as a small, easy-to-script-for test stand-in for the updater */
await ImageService.fetchImage('alpine')
})
describe('when a container runs successfully', () => {
beforeEach(async () => {
container = await docker.createContainer({
Image: 'alpine',
AttachStdout: true,
AttachStderr: true,
Cmd: ['/bin/sh', '-c', 'echo $VAR'],
Env: ['VAR=env-var']
})
})
test('it returns true', async () => {
expect(await ContainerService.run(container)).toBe(true)
})
})
describe('when a container runs unsuccessfully', () => {
beforeEach(async () => {
container = await docker.createContainer({
Image: 'alpine',
AttachStdout: true,
AttachStderr: true,
Cmd: ['/bin/sh', '-c', 'nosuchccommand']
})
})
test('raises an exception', async () => {
await expect(ContainerService.run(container)).rejects.toThrow(
/Failure running container/
)
})
})
})