-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.js
105 lines (82 loc) · 2.36 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var docker = require('./index')
var expect = require('chai').expect
var nock = require('nock')
var host = "http://localhost:4243"
describe("docker.js", function() {
describe("#containers", function() {
describe("#createContainer", function() {
var opts = {
"Hostname":"",
"User":"",
"Memory":0,
"MemorySwap":0,
"AttachStdin":false,
"AttachStdout":true,
"AttachStderr":true,
"PortSpecs":null,
"Tty":false,
"OpenStdin":false,
"StdinOnce":false,
"Env":null,
"Cmd":[
"date"
],
"Dns":null,
"Image":"base",
"Volumes":{},
"VolumesFrom":""
}
it("should create a new container", function(done) {
var res = {Id:"abcde", Warnings:[]}
var scope = nock(host).post('/containers/create').reply(201, res)
function handler(err, r) {
expect(err).to.be.null
expect(r).to.include.keys(['Id', 'Warnings'])
scope.done()
done()
}
docker().createContainer(opts, handler)
})
})
describe("#listContainers", function() {
var containers = [
{
"Id": "8dfafdbc3a40",
"Image": "base:latest",
"Command": "echo 1",
"Created": 1367854155,
"Status": "Exit 0"
},
{
"Id": "9cd87474be90",
"Image": "base:latest",
"Command": "echo 222222",
"Created": 1367854155,
"Status": "Exit 0"
},
]
it("should list containers", function(done) {
var scope = nock(host).get('/containers/ps').reply(200, containers)
function gotContainers(err, c) {
expect(err).to.be.null
expect(c).to.have.length(2)
expect(c[0]).to.include.keys(Object.keys(containers[0]))
expect(c[1]).to.include.keys(Object.keys(containers[1]))
scope.done()
done()
}
docker().listContainers(gotContainers)
})
it("should error on non-200 from server", function(done) {
var scope = nock(host).get('/containers/ps').reply(500, [])
function gotContainers(err, c) {
expect(err).to.exist
expect(c).to.eql([])
scope.done()
done()
}
docker().listContainers(gotContainers)
})
})
})
})