docker-api 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -48
- data/lib/docker/connection.rb +8 -1
- data/lib/docker/container.rb +11 -12
- data/lib/docker/error.rb +0 -4
- data/lib/docker/image.rb +44 -30
- data/lib/docker/model.rb +30 -40
- data/lib/docker/version.rb +1 -1
- data/spec/docker/connection_spec.rb +3 -2
- data/spec/docker/container_spec.rb +206 -377
- data/spec/docker/image_spec.rb +123 -237
- data/spec/vcr/Docker_Container/_all/when_the_HTTP_response_is_a_200/materializes_each_Container_into_a_Docker_Container.yml +2503 -263
- data/spec/vcr/Docker_Container/_attach/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/yields_each_chunk.yml +30 -22
- data/spec/vcr/Docker_Container/_changes/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/returns_the_changes_as_an_array.yml +41 -33
- data/spec/vcr/Docker_Container/_commit/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/creates_a_new_Image_from_the_Container_s_changes.yml +34 -28
- data/spec/vcr/Docker_Container/{_create_ → _create}/when_the_Container_does_not_yet_exist_and_the_body_is_a_Hash/when_the_HTTP_request_returns_a_200/sets_the_id.yml +11 -9
- data/spec/vcr/Docker_Container/_export/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/yields_each_chunk.yml +43 -29
- data/spec/vcr/Docker_Container/_json/when_the_HTTP_response_status_is_200/returns_the_description_as_a_Hash.yml +63 -0
- data/spec/vcr/Docker_Container/_kill/when_the_HTTP_response_status_is_204/kills_the_container.yml +1358 -0
- data/spec/vcr/Docker_Container/_restart/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_204 → when_the_HTTP_response_status_is_204}/restarts_the_container.yml +73 -59
- data/spec/vcr/Docker_Container/_start/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/starts_the_container.yml +33 -28
- data/spec/vcr/Docker_Container/_stop/when_the_HTTP_response_status_is_204/stops_the_container.yml +1387 -0
- data/spec/vcr/Docker_Container/_wait/{when_the_Container_has_been_created/when_the_HTTP_response_status_is_200 → when_the_HTTP_response_status_is_200}/waits_for_the_command_to_finish.yml +31 -25
- data/spec/vcr/Docker_Image/_all/when_the_HTTP_response_is_a_200/materializes_each_Image_into_a_Docker_Image.yml +6 -6
- data/spec/vcr/Docker_Image/_build/with_a_valid_Dockerfile/builds_an_image.yml +4 -4
- data/spec/vcr/Docker_Image/_build/with_an_invalid_Dockerfile/throws_a_UnexpectedResponseError.yml +4 -4
- data/spec/vcr/Docker_Image/_build_from_dir/with_a_valid_Dockerfile/builds_the_image.yml +14 -14
- data/spec/vcr/Docker_Image/_create/when_the_Image_does_not_yet_exist_and_the_body_is_a_Hash/when_the_HTTP_request_returns_a_200/sets_the_id.yml +33 -0
- data/spec/vcr/Docker_Image/_history/when_the_HTTP_response_status_is_200/returns_the_history_of_the_Image.yml +63 -0
- data/spec/vcr/Docker_Image/_import/when_the_file_does_exist/creates_the_Image.yml +11 -9
- data/spec/vcr/Docker_Image/_insert/when_the_HTTP_response_status_is_200/inserts_the_url_s_file_into_a_new_Image.yml +220 -0
- data/spec/vcr/Docker_Image/_json/when_the_HTTP_response_status_is_200/returns_additional_information_about_image_image.yml +63 -0
- data/spec/vcr/Docker_Image/_remove/when_the_HTTP_response_status_is_204/removes_the_Image.yml +93 -0
- data/spec/vcr/Docker_Image/_remove/when_the_Image_has_been_created/when_the_HTTP_response_status_is_204/removes_the_Image.yml +63 -0
- data/spec/vcr/Docker_Image/_run/when_the_Image_has_been_created/when_the_argument_is_a_String/splits_the_String_by_spaces_and_creates_a_new_Container.yml +119 -0
- data/spec/vcr/Docker_Image/_run/when_the_Image_has_been_created/when_the_argument_is_an_Array/creates_a_new_Container.yml +119 -0
- data/spec/vcr/Docker_Image/_run/when_the_argument_is_a_String/splits_the_String_by_spaces_and_creates_a_new_Container.yml +119 -0
- data/spec/vcr/Docker_Image/_run/when_the_argument_is_an_Array/creates_a_new_Container.yml +119 -0
- data/spec/vcr/Docker_Image/_tag/when_the_HTTP_response_status_is_200/tags_the_image_with_the_repo_name.yml +63 -0
- metadata +46 -29
- data/spec/vcr/Docker_Container/_json/when_the_Container_has_been_created/when_the_HTTP_response_status_is_200/returns_the_description_as_a_Hash.yml +0 -61
- data/spec/vcr/Docker_Container/_kill/when_the_Container_has_been_created/when_the_HTTP_response_status_is_204/kills_the_container.yml +0 -232
- data/spec/vcr/Docker_Container/_stop/when_the_Container_has_been_created/when_the_HTTP_response_status_is_204/stops_the_container.yml +0 -259
data/lib/docker/version.rb
CHANGED
@@ -45,8 +45,9 @@ describe Docker::Connection do
|
|
45
45
|
[:get, :put, :post, :delete].each do |method|
|
46
46
|
describe "##{method}" do
|
47
47
|
it 'is delegated to #resource' do
|
48
|
-
subject.
|
49
|
-
subject.public_send(
|
48
|
+
subject.should_receive(:reset!)
|
49
|
+
subject.stub_chain(:resource, :public_send).and_return(:lol)
|
50
|
+
subject.public_send(method).should == :lol
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -3,501 +3,329 @@ require 'spec_helper'
|
|
3
3
|
# WARNING if you're re-recording any of these VCRs, you must be running the
|
4
4
|
# Docker daemon and have the base Image pulled.
|
5
5
|
describe Docker::Container do
|
6
|
-
|
7
|
-
subject { described_class }
|
8
|
-
|
9
|
-
context 'with no argument' do
|
10
|
-
let(:container) { subject.new }
|
11
|
-
|
12
|
-
it 'sets the id to nil' do
|
13
|
-
container.id.should be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'keeps the default Connection' do
|
17
|
-
container.connection.should == Docker.connection
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with an argument' do
|
22
|
-
let(:id) { 'a7c2ee4' }
|
23
|
-
let(:container) { subject.new(:id => id) }
|
24
|
-
|
25
|
-
it 'sets the id to the argument' do
|
26
|
-
container.id.should == id
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'keeps the default Connection' do
|
30
|
-
container.connection.should == Docker.connection
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with two arguments' do
|
35
|
-
context 'when the second argument is not a Docker::Connection' do
|
36
|
-
let(:id) { 'abc123f' }
|
37
|
-
let(:connection) { :not_a_connection }
|
38
|
-
let(:container) { subject.new(:id => id, :connection => connection) }
|
39
|
-
|
40
|
-
it 'raises an error' do
|
41
|
-
expect { container }.to raise_error(Docker::Error::ArgumentError)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'when the second argument is a Docker::Connection' do
|
46
|
-
let(:id) { 'cb3f14a' }
|
47
|
-
let(:connection) { Docker::Connection.new }
|
48
|
-
let(:container) { subject.new(:id => id, :connection => connection) }
|
49
|
-
|
50
|
-
it 'initializes the Container' do
|
51
|
-
container.id.should == id
|
52
|
-
container.connection.should == connection
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
6
|
+
subject { described_class.send(:new, :id => rand(10000).to_s) }
|
57
7
|
|
58
8
|
describe '#to_s' do
|
59
9
|
let(:id) { 'bf119e2' }
|
60
10
|
let(:connection) { Docker::Connection.new }
|
61
|
-
let(:expected_string)
|
11
|
+
let(:expected_string) {
|
62
12
|
"Docker::Container { :id => #{id}, :connection => #{connection} }"
|
13
|
+
}
|
14
|
+
before do
|
15
|
+
{
|
16
|
+
:@id => id,
|
17
|
+
:@connection => connection
|
18
|
+
}.each { |k, v| subject.instance_variable_set(k, v) }
|
63
19
|
end
|
64
|
-
subject { described_class.new(:id => id, :connection => connection) }
|
65
20
|
|
66
21
|
its(:to_s) { should == expected_string }
|
67
22
|
end
|
68
23
|
|
69
|
-
describe '#created?' do
|
70
|
-
context 'when the id is nil' do
|
71
|
-
its(:created?) { should be_false }
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when the id is present' do
|
75
|
-
subject { described_class.new(:id => 'a732ebf') }
|
76
|
-
|
77
|
-
its(:created?) { should be_true }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#create!' do
|
82
|
-
context 'when the Container has already been created' do
|
83
|
-
subject { described_class.new(:id => '5e88b2a') }
|
84
|
-
|
85
|
-
it 'raises an error' do
|
86
|
-
expect { subject.create! }
|
87
|
-
.to raise_error(Docker::Error::StateError)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'when the body is not a Hash' do
|
92
|
-
it 'raises an error' do
|
93
|
-
expect { subject.create!(:not_a_hash) }
|
94
|
-
.to raise_error(Docker::Error::ArgumentError)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when the Container does not yet exist and the body is a Hash' do
|
99
|
-
context 'when the HTTP request does not return a 200' do
|
100
|
-
before { Excon.stub({ :method => :post }, { :status => 400 }) }
|
101
|
-
after { Excon.stubs.shift }
|
102
|
-
|
103
|
-
it 'raises an error' do
|
104
|
-
expect { subject.create! }.to raise_error(Docker::Error::ClientError)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'when the HTTP request returns a 200' do
|
109
|
-
let(:options) do
|
110
|
-
{
|
111
|
-
"Hostname" => "",
|
112
|
-
"User" => "",
|
113
|
-
"Memory" => 0,
|
114
|
-
"MemorySwap" => 0,
|
115
|
-
"AttachStdin" => false,
|
116
|
-
"AttachStdout" => false,
|
117
|
-
"AttachStderr" => false,
|
118
|
-
"PortSpecs" => nil,
|
119
|
-
"Tty" => false,
|
120
|
-
"OpenStdin" => false,
|
121
|
-
"StdinOnce" => false,
|
122
|
-
"Env" => nil,
|
123
|
-
"Cmd" => ["date"],
|
124
|
-
"Dns" => nil,
|
125
|
-
"Image" => "base",
|
126
|
-
"Volumes" => {},
|
127
|
-
"VolumesFrom" => ""
|
128
|
-
}
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'sets the id', :vcr do
|
132
|
-
expect { subject.create!(options) }
|
133
|
-
.to change { subject.id }
|
134
|
-
.from(nil)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
24
|
describe '#json' do
|
141
|
-
context 'when the
|
25
|
+
context 'when the HTTP response status is not 200' do
|
26
|
+
before { Excon.stub({ :method => :get }, { :status => 500 }) }
|
27
|
+
after { Excon.stubs.shift }
|
28
|
+
|
142
29
|
it 'raises an error' do
|
143
|
-
expect { subject.json }
|
30
|
+
expect { subject.json }
|
31
|
+
.to raise_error(Docker::Error::ServerError)
|
144
32
|
end
|
145
33
|
end
|
146
34
|
|
147
|
-
context 'when the
|
148
|
-
|
149
|
-
|
150
|
-
subject.stub(:created?).and_return(true)
|
151
|
-
Excon.stub({ :method => :get }, { :status => 500 })
|
152
|
-
end
|
153
|
-
after { Excon.stubs.shift }
|
154
|
-
|
155
|
-
it 'raises an error' do
|
156
|
-
expect { subject.json }
|
157
|
-
.to raise_error(Docker::Error::ServerError)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when the HTTP response status is 200' do
|
162
|
-
let(:description) { subject.json }
|
163
|
-
before { subject.create!('Cmd' => ['ls'], 'Image' => 'base') }
|
35
|
+
context 'when the HTTP response status is 200' do
|
36
|
+
subject { described_class.create('Cmd' => %w[true], 'Image' => 'base') }
|
37
|
+
let(:description) { subject.json }
|
164
38
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
39
|
+
it 'returns the description as a Hash', :vcr do
|
40
|
+
description.should be_a(Hash)
|
41
|
+
description['ID'].should start_with(subject.id)
|
169
42
|
end
|
170
43
|
end
|
171
44
|
end
|
172
45
|
|
173
46
|
describe '#changes' do
|
174
|
-
context 'when the
|
47
|
+
context 'when the HTTP response status is not 200' do
|
48
|
+
before { Excon.stub({ :method => :get }, { :status => 500 }) }
|
49
|
+
after { Excon.stubs.shift }
|
50
|
+
|
175
51
|
it 'raises an error' do
|
176
52
|
expect { subject.changes }
|
177
|
-
.to raise_error
|
53
|
+
.to raise_error(Docker::Error::ServerError)
|
178
54
|
end
|
179
55
|
end
|
180
56
|
|
181
|
-
context 'when the
|
182
|
-
|
183
|
-
|
184
|
-
subject.stub(:created?).and_return(true)
|
185
|
-
Excon.stub({ :method => :get }, { :status => 500 })
|
186
|
-
end
|
187
|
-
after { Excon.stubs.shift }
|
57
|
+
context 'when the HTTP response status is 200' do
|
58
|
+
subject { described_class.create('Cmd' => %w[true], 'Image' => 'base') }
|
59
|
+
let(:changes) { subject.changes }
|
188
60
|
|
189
|
-
|
190
|
-
expect { subject.changes }
|
191
|
-
.to raise_error(Docker::Error::ServerError)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'when the HTTP response status is 200' do
|
196
|
-
let(:changes) { subject.changes }
|
197
|
-
before do
|
198
|
-
subject.create!('Cmd' => ['ls'], 'Image' => 'base')
|
199
|
-
subject.start
|
200
|
-
subject.wait
|
201
|
-
end
|
61
|
+
before { subject.tap(&:start).tap(&:wait) }
|
202
62
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
end
|
63
|
+
it 'returns the changes as an array', :vcr do
|
64
|
+
changes.should be_a Array
|
65
|
+
changes.should be_all { |change| change.is_a?(Hash) }
|
66
|
+
changes.length.should_not be_zero
|
208
67
|
end
|
209
68
|
end
|
210
69
|
end
|
211
70
|
|
212
71
|
describe '#export' do
|
213
|
-
context 'when the
|
72
|
+
context 'when the HTTP response status is not 200' do
|
73
|
+
before { Excon.stub({ :method => :get }, { :status => 500 }) }
|
74
|
+
after { Excon.stubs.shift }
|
75
|
+
|
214
76
|
it 'raises an error' do
|
215
77
|
expect { subject.export { } }
|
216
|
-
.to raise_error
|
78
|
+
.to raise_error(Docker::Error::ServerError)
|
217
79
|
end
|
218
80
|
end
|
219
81
|
|
220
|
-
context 'when the
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
after { Excon.stubs.shift }
|
82
|
+
context 'when the HTTP response status is 200' do
|
83
|
+
subject {
|
84
|
+
Docker::Container.create('Cmd' => %w[rm -rf / --no-preserve-root],
|
85
|
+
'Image' => 'base')
|
86
|
+
}
|
87
|
+
before { subject.start }
|
227
88
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
context 'when the HTTP response status is 200' do
|
235
|
-
before do
|
236
|
-
subject.create!('Cmd' => %w[rm -rf / --no-preserve-root],
|
237
|
-
'Image' => 'base')
|
238
|
-
subject.start
|
239
|
-
end
|
240
|
-
|
241
|
-
it 'yields each chunk', :vcr do
|
242
|
-
first = nil
|
243
|
-
subject.export do |chunk|
|
244
|
-
first = chunk
|
245
|
-
break
|
246
|
-
end
|
247
|
-
first[257..261].should == "ustar" # Make sure the export is a tar.
|
89
|
+
it 'yields each chunk', :vcr do
|
90
|
+
first = nil
|
91
|
+
subject.export do |chunk|
|
92
|
+
first = chunk
|
93
|
+
break
|
248
94
|
end
|
95
|
+
first[257..261].should == "ustar" # Make sure the export is a tar.
|
249
96
|
end
|
250
97
|
end
|
251
98
|
end
|
252
99
|
|
253
100
|
describe '#attach' do
|
254
|
-
context 'when the
|
101
|
+
context 'when the HTTP response status is not 200' do
|
102
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
103
|
+
after { Excon.stubs.shift }
|
104
|
+
|
255
105
|
it 'raises an error' do
|
256
106
|
expect { subject.attach { } }
|
257
|
-
.to raise_error
|
107
|
+
.to raise_error(Docker::Error::ServerError)
|
258
108
|
end
|
259
109
|
end
|
260
110
|
|
261
|
-
context 'when the
|
262
|
-
|
263
|
-
|
264
|
-
subject.stub(:created?).and_return(true)
|
265
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
266
|
-
end
|
267
|
-
after { Excon.stubs.shift }
|
268
|
-
|
269
|
-
it 'raises an error' do
|
270
|
-
expect { subject.attach { } }
|
271
|
-
.to raise_error(Docker::Error::ServerError)
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context 'when the HTTP response status is 200' do
|
276
|
-
before { subject.create!('Cmd' => %w[uname -r], 'Image' => 'base') }
|
111
|
+
context 'when the HTTP response status is 200' do
|
112
|
+
subject { described_class.create('Cmd' => %w[uname -r],
|
113
|
+
'Image' => 'base') }
|
277
114
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
115
|
+
it 'yields each chunk', :vcr do
|
116
|
+
subject.tap(&:start).attach { |chunk|
|
117
|
+
chunk.should == "3.8.0-25-generic\n"
|
118
|
+
}
|
283
119
|
end
|
284
120
|
end
|
285
121
|
end
|
286
122
|
|
287
123
|
describe '#start' do
|
288
|
-
context 'when the
|
124
|
+
context 'when the HTTP response status is not 200' do
|
125
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
126
|
+
after { Excon.stubs.shift }
|
127
|
+
|
289
128
|
it 'raises an error' do
|
290
|
-
expect { subject.start }
|
129
|
+
expect { subject.start }
|
130
|
+
.to raise_error(Docker::Error::ServerError)
|
291
131
|
end
|
292
132
|
end
|
293
133
|
|
294
|
-
context 'when the
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
299
|
-
end
|
300
|
-
after { Excon.stubs.shift }
|
301
|
-
|
302
|
-
it 'raises an error' do
|
303
|
-
expect { subject.start }
|
304
|
-
.to raise_error(Docker::Error::ServerError)
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
context 'when the HTTP response status is 200' do
|
309
|
-
before { subject.create!('Cmd' => ['/usr/bin/sleep 10'],
|
310
|
-
'Image' => 'base') }
|
134
|
+
context 'when the HTTP response status is 200' do
|
135
|
+
subject {
|
136
|
+
described_class.create('Cmd' => %w[true], 'Image' => 'base')
|
137
|
+
}
|
311
138
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
end
|
139
|
+
it 'starts the container', :vcr do
|
140
|
+
subject.start
|
141
|
+
described_class.all.map(&:id).should be_any { |id|
|
142
|
+
id.start_with?(subject.id)
|
143
|
+
}
|
318
144
|
end
|
319
145
|
end
|
320
146
|
end
|
321
147
|
|
322
148
|
describe '#stop' do
|
323
|
-
context 'when the
|
149
|
+
context 'when the HTTP response status is not 204' do
|
150
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
151
|
+
after { Excon.stubs.shift }
|
152
|
+
|
324
153
|
it 'raises an error' do
|
325
|
-
expect { subject.stop }
|
154
|
+
expect { subject.stop }
|
155
|
+
.to raise_error(Docker::Error::ServerError)
|
326
156
|
end
|
327
157
|
end
|
328
158
|
|
329
|
-
context 'when the
|
330
|
-
|
331
|
-
before do
|
332
|
-
subject.stub(:created?).and_return(true)
|
333
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
334
|
-
end
|
335
|
-
after { Excon.stubs.shift }
|
336
|
-
|
337
|
-
it 'raises an error' do
|
338
|
-
expect { subject.stop }
|
339
|
-
.to raise_error(Docker::Error::ServerError)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
context 'when the HTTP response status is 204' do
|
344
|
-
before { subject.create!('Cmd' => ['ls'], 'Image' => 'base') }
|
159
|
+
context 'when the HTTP response status is 204' do
|
160
|
+
subject { described_class.create('Cmd' => %w[ls], 'Image' => 'base') }
|
345
161
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
end
|
162
|
+
it 'stops the container', :vcr do
|
163
|
+
subject.tap(&:start).stop
|
164
|
+
described_class.all(:all => true).map(&:id).should be_any { |id|
|
165
|
+
id.start_with?(subject.id)
|
166
|
+
}
|
167
|
+
described_class.all.map(&:id).should be_none { |id|
|
168
|
+
id.start_with?(subject.id)
|
169
|
+
}
|
355
170
|
end
|
356
171
|
end
|
357
172
|
end
|
358
173
|
|
359
174
|
describe '#kill' do
|
360
|
-
context 'when the
|
175
|
+
context 'when the HTTP response status is not 204' do
|
176
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
177
|
+
after { Excon.stubs.shift }
|
178
|
+
|
361
179
|
it 'raises an error' do
|
362
|
-
expect { subject.kill }
|
180
|
+
expect { subject.kill }
|
181
|
+
.to raise_error(Docker::Error::ServerError)
|
363
182
|
end
|
364
183
|
end
|
365
184
|
|
366
|
-
context 'when the
|
367
|
-
|
368
|
-
before do
|
369
|
-
subject.stub(:created?).and_return(true)
|
370
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
371
|
-
end
|
372
|
-
after { Excon.stubs.shift }
|
373
|
-
|
374
|
-
it 'raises an error' do
|
375
|
-
expect { subject.kill }
|
376
|
-
.to raise_error(Docker::Error::ServerError)
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
context 'when the HTTP response status is 204' do
|
381
|
-
before { subject.create!('Cmd' => ['ls'], 'Image' => 'base') }
|
185
|
+
context 'when the HTTP response status is 204' do
|
186
|
+
subject { described_class.create('Cmd' => ['ls'], 'Image' => 'base') }
|
382
187
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
end
|
188
|
+
it 'kills the container', :vcr do
|
189
|
+
subject.kill
|
190
|
+
described_class.all.map(&:id).should be_none { |id|
|
191
|
+
id.start_with?(subject.id)
|
192
|
+
}
|
193
|
+
described_class.all(:all => true).map(&:id).should be_any { |id|
|
194
|
+
id.start_with?(subject.id)
|
195
|
+
}
|
392
196
|
end
|
393
197
|
end
|
394
198
|
end
|
395
199
|
|
396
200
|
describe '#restart' do
|
397
|
-
context 'when the
|
201
|
+
context 'when the HTTP response status is not 204' do
|
202
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
203
|
+
after { Excon.stubs.shift }
|
204
|
+
|
398
205
|
it 'raises an error' do
|
399
|
-
expect { subject.restart }
|
206
|
+
expect { subject.restart }
|
207
|
+
.to raise_error(Docker::Error::ServerError)
|
400
208
|
end
|
401
209
|
end
|
402
210
|
|
403
|
-
context 'when the
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
end
|
409
|
-
after { Excon.stubs.shift }
|
410
|
-
|
411
|
-
it 'raises an error' do
|
412
|
-
expect { subject.restart }
|
413
|
-
.to raise_error(Docker::Error::ServerError)
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
context 'when the HTTP response status is 204' do
|
418
|
-
before { subject.create!('Cmd' => ['/usr/bin/sleep 50'],
|
419
|
-
'Image' => 'base') }
|
211
|
+
context 'when the HTTP response status is 204' do
|
212
|
+
subject {
|
213
|
+
described_class.create('Cmd' => %w[/usr/bin/sleep 50],
|
214
|
+
'Image' => 'base')
|
215
|
+
}
|
420
216
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
end
|
217
|
+
it 'restarts the container', :vcr do
|
218
|
+
subject.start
|
219
|
+
described_class.all.map(&:id).should be_any { |id|
|
220
|
+
id.start_with?(subject.id)
|
221
|
+
}
|
222
|
+
subject.stop
|
223
|
+
described_class.all.map(&:id).should be_none { |id|
|
224
|
+
id.start_with?(subject.id)
|
225
|
+
}
|
226
|
+
subject.restart
|
227
|
+
described_class.all.map(&:id).should be_any { |id|
|
228
|
+
id.start_with?(subject.id)
|
229
|
+
}
|
435
230
|
end
|
436
231
|
end
|
437
232
|
end
|
438
233
|
|
439
234
|
describe '#wait' do
|
440
|
-
context 'when the
|
235
|
+
context 'when the HTTP response status is not 200' do
|
236
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
237
|
+
after { Excon.stubs.shift }
|
238
|
+
|
441
239
|
it 'raises an error' do
|
442
|
-
expect { subject.wait }
|
240
|
+
expect { subject.wait }
|
241
|
+
.to raise_error(Docker::Error::ServerError)
|
443
242
|
end
|
444
243
|
end
|
445
244
|
|
446
|
-
context 'when the
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
451
|
-
end
|
452
|
-
after { Excon.stubs.shift }
|
245
|
+
context 'when the HTTP response status is 200' do
|
246
|
+
subject {
|
247
|
+
described_class.create('Cmd' => %w[tar nonsense],
|
248
|
+
'Image' => 'base') }
|
453
249
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
end
|
250
|
+
it 'waits for the command to finish', :vcr do
|
251
|
+
subject.start
|
252
|
+
subject.wait['StatusCode'].should == 64
|
458
253
|
end
|
254
|
+
end
|
255
|
+
end
|
459
256
|
|
460
|
-
|
461
|
-
|
462
|
-
|
257
|
+
describe '#commit' do
|
258
|
+
context 'when the HTTP response status is not 200' do
|
259
|
+
before { Excon.stub({ :method => :post }, { :status => 500 }) }
|
260
|
+
after { Excon.stubs.shift }
|
463
261
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
262
|
+
it 'raises an error' do
|
263
|
+
expect { subject.commit }
|
264
|
+
.to raise_error(Docker::Error::ServerError)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'when the HTTP response status is 200' do
|
269
|
+
let(:image) { subject.commit }
|
270
|
+
subject { described_class.create('Cmd' => %w[ls], 'Image' => 'base') }
|
271
|
+
|
272
|
+
before { subject.start }
|
273
|
+
|
274
|
+
it 'creates a new Image from the Container\'s changes', :vcr do
|
275
|
+
image.should be_a Docker::Image
|
276
|
+
image.id.should_not be_nil
|
468
277
|
end
|
469
278
|
end
|
470
279
|
end
|
471
280
|
|
472
|
-
describe '
|
473
|
-
|
281
|
+
describe '.create' do
|
282
|
+
subject { described_class }
|
283
|
+
|
284
|
+
context 'when the body is not a Hash' do
|
474
285
|
it 'raises an error' do
|
475
|
-
expect { subject.
|
286
|
+
expect { subject.create(:not_a_hash) }
|
287
|
+
.to raise_error(Docker::Error::ArgumentError)
|
476
288
|
end
|
477
289
|
end
|
478
290
|
|
479
|
-
context 'when the Container
|
480
|
-
context 'when the HTTP
|
481
|
-
before
|
482
|
-
subject.stub(:id).and_return('abc')
|
483
|
-
Excon.stub({ :method => :post }, { :status => 500 })
|
484
|
-
end
|
291
|
+
context 'when the Container does not yet exist and the body is a Hash' do
|
292
|
+
context 'when the HTTP request does not return a 200' do
|
293
|
+
before { Excon.stub({ :method => :post }, { :status => 400 }) }
|
485
294
|
after { Excon.stubs.shift }
|
486
295
|
|
487
296
|
it 'raises an error' do
|
488
|
-
expect { subject.
|
489
|
-
.to raise_error(Docker::Error::ServerError)
|
297
|
+
expect { subject.create }.to raise_error(Docker::Error::ClientError)
|
490
298
|
end
|
491
299
|
end
|
492
300
|
|
493
|
-
context 'when the HTTP
|
494
|
-
let(:
|
495
|
-
|
301
|
+
context 'when the HTTP request returns a 200' do
|
302
|
+
let(:options) do
|
303
|
+
{
|
304
|
+
"Hostname" => "",
|
305
|
+
"User" => "",
|
306
|
+
"Memory" => 0,
|
307
|
+
"MemorySwap" => 0,
|
308
|
+
"AttachStdin" => false,
|
309
|
+
"AttachStdout" => false,
|
310
|
+
"AttachStderr" => false,
|
311
|
+
"PortSpecs" => nil,
|
312
|
+
"Tty" => false,
|
313
|
+
"OpenStdin" => false,
|
314
|
+
"StdinOnce" => false,
|
315
|
+
"Env" => nil,
|
316
|
+
"Cmd" => ["date"],
|
317
|
+
"Dns" => nil,
|
318
|
+
"Image" => "base",
|
319
|
+
"Volumes" => {},
|
320
|
+
"VolumesFrom" => ""
|
321
|
+
}
|
322
|
+
end
|
323
|
+
let(:container) { subject.create(options) }
|
496
324
|
|
497
|
-
it '
|
498
|
-
|
499
|
-
|
500
|
-
|
325
|
+
it 'sets the id', :vcr do
|
326
|
+
container.should be_a Docker::Container
|
327
|
+
container.id.should_not be_nil
|
328
|
+
container.connection.should_not be_nil
|
501
329
|
end
|
502
330
|
end
|
503
331
|
end
|
@@ -517,8 +345,9 @@ describe Docker::Container do
|
|
517
345
|
end
|
518
346
|
|
519
347
|
context 'when the HTTP response is a 200' do
|
348
|
+
before { described_class.create('Cmd' => ['ls'], 'Image' => 'base') }
|
349
|
+
|
520
350
|
it 'materializes each Container into a Docker::Container', :vcr do
|
521
|
-
subject.new.create!('Cmd' => ['ls'], 'Image' => 'base')
|
522
351
|
subject.all(:all => true).should be_all { |container|
|
523
352
|
container.is_a?(Docker::Container)
|
524
353
|
}
|