UNPKG

1.9 kBJavaScriptView Raw
1import test from 'ava'
2import fs from 'fs'
3import { Image } from '../lib/image'
4import { Docker } from '../lib/docker'
5
6const socket = process.env.DOCKER_SOCKET || '/var/run/docker.sock'
7const isSocket = fs.existsSync(socket) ? fs.statSync(socket).isSocket() : false
8const docker = isSocket
9 ? new Docker()
10 : new Docker({ socketPath: socket })
11const testImage = 'ubuntu:latest'
12
13test('list', async t => {
14 const images = await docker.image.list()
15 t.is(images.constructor, Array)
16})
17
18test('create', async t => {
19 const stream = await docker.image.create({}, { fromImage: 'ubuntu' })
20 t.truthy(stream.pipe)
21})
22
23test('status', async t => {
24 const image = await docker.image.get(testImage).status()
25 t.is(image.constructor, Image)
26})
27
28test('history', async t => {
29 const history = await docker.image.get(testImage).history()
30 t.is(history.constructor, Array)
31})
32
33test('tag', async t => {
34 const image = await docker.image.get(testImage).tag({ tag: 'test', repo: 'root' })
35 t.is(image.constructor, Image)
36 t.not(image.data.RepoTags.indexOf('root:test'), -1)
37})
38
39test('search', async t => {
40 const images = await docker.image.search({ term: 'ubuntu' })
41 t.is(images.constructor, Array)
42})
43
44test('load', async t => {
45 const stream = await docker.image.build(fs.createReadStream('./test/test.tar'))
46 t.truthy(stream.pipe)
47})
48
49test('build', async t => {
50 const result = await docker.image.build('./test/test.tar', { t: 'test' })
51 .then((stream) => {
52 t.truthy(stream.pipe)
53
54 return new Promise((resolve, reject) => {
55 const res = []
56 stream.on('end',() => resolve(Buffer.concat(res).toString()))
57 stream.on('data', (d) => res.push(d))
58 stream.on('error', reject)
59 })
60 })
61 const image = await docker.image.get('test').status()
62 t.notThrows(image.remove())
63})
64
65test.after('prune', async t => {
66 t.truthy(await docker.image.prune())
67})