-
-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathpromises.js
141 lines (120 loc) · 3.41 KB
/
promises.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*jshint -W030 */
var expect = require('chai').expect;
var docker = require('./spec_helper').docker;
var dockerp = require('./spec_helper').dockerp;
var MemoryStream = require('memorystream');
var Socket = require('net').Socket;
var testImage = 'ubuntu:latest';
describe("#promises", function() {
describe("#docker", function() {
it("should build image from readable stream", function(done) {
this.timeout(60000);
var data = require('fs').createReadStream('./test/test.tar');
docker.buildImage(data).then(function(stream) {
expect(stream).to.be.ok;
stream.pipe(process.stdout, {
end: true
});
stream.on('end', function() {
done();
});
}).catch(function(err) {
expect(err).to.be.null;
done();
});
});
});
it("should build image from multiple files", function(done) {
this.timeout(60000);
docker.buildImage({
context: __dirname,
src: ['Dockerfile']
}).then(function(stream) {
expect(stream).to.be.ok;
stream.pipe(process.stdout, {
end: true
});
stream.on('end', function() {
done();
});
}).catch(function(err) {
expect(err).to.be.null;
done();
});
});
describe("#container", function() {
it("should start->resize->stop->remove a container", function(done) {
this.timeout(60000);
var containeri;
docker.createContainer({
Image: 'ubuntu',
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: true,
Cmd: ['/bin/bash', '-c', 'sleep 60'],
OpenStdin: false,
StdinOnce: false
}).then(function(container) {
containeri = container;
return containeri.start();
}).then(function(data) {
return containeri.resize({
h: 10,
w: 10
});
}).then(function(data) {
return containeri.stop();
}).then(function(data) {
return containeri.remove();
}).then(function(data) {
done();
}).catch(function(err) {
expect(err).to.be.null;
done();
});
});
it("should runPromise a command", function(done) {
this.timeout(30000);
docker.run(testImage, ['bash', '-c', 'uname -a'], process.stdout).then(function(data) {
var output = data[0];
var container = data[1];
expect(container).to.be.ok;
return container.remove();
}).then(function(data) {
done();
}).catch(function(err) {
expect(err).to.be.null;
done();
});
});
});
describe("#custom Promise (bluebird)", function() {
it("should start->stop->remove a container with Bluebird", function(done) {
this.timeout(60000);
var containeri;
dockerp.createContainer({
Image: 'ubuntu',
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: true,
Cmd: ['/bin/bash', '-c', 'tail -f /etc/resolv.conf'],
OpenStdin: false,
StdinOnce: false
}).then(function(container) {
containeri = container;
return containeri.start();
}).then(function(data) {
return containeri.stop();
}).then(function(data) {
return containeri.remove();
}).then(function(data) {
done();
}).catch(function(err) {
expect(err).to.be.null;
done();
});
});
});
});