1 | import test from 'ava'
|
2 | import fs from 'fs'
|
3 | import { Image } from '../lib/image'
|
4 | import { Docker } from '../lib/docker'
|
5 |
|
6 | const socket = process.env.DOCKER_SOCKET || '/var/run/docker.sock'
|
7 | const isSocket = fs.existsSync(socket) ? fs.statSync(socket).isSocket() : false
|
8 | const docker = isSocket
|
9 | ? new Docker()
|
10 | : new Docker({ socketPath: socket })
|
11 | const testImage = 'ubuntu:latest'
|
12 |
|
13 | test('list', async t => {
|
14 | const images = await docker.image.list()
|
15 | t.is(images.constructor, Array)
|
16 | })
|
17 |
|
18 | test('create', async t => {
|
19 | const stream = await docker.image.create({}, { fromImage: 'ubuntu' })
|
20 | t.truthy(stream.pipe)
|
21 | })
|
22 |
|
23 | test('status', async t => {
|
24 | const image = await docker.image.get(testImage).status()
|
25 | t.is(image.constructor, Image)
|
26 | })
|
27 |
|
28 | test('history', async t => {
|
29 | const history = await docker.image.get(testImage).history()
|
30 | t.is(history.constructor, Array)
|
31 | })
|
32 |
|
33 | test('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 |
|
39 | test('search', async t => {
|
40 | const images = await docker.image.search({ term: 'ubuntu' })
|
41 | t.is(images.constructor, Array)
|
42 | })
|
43 |
|
44 | test('load', async t => {
|
45 | const stream = await docker.image.build(fs.createReadStream('./test/test.tar'))
|
46 | t.truthy(stream.pipe)
|
47 | })
|
48 |
|
49 | test('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 |
|
65 | test.after('prune', async t => {
|
66 | t.truthy(await docker.image.prune())
|
67 | })
|