docker-api 1.28.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,258 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Docker do
4
- subject { Docker }
5
-
6
- it { should be_a Module }
7
-
8
- context 'default url and connection' do
9
- context "when the DOCKER_* ENV variables aren't set" do
10
- before do
11
- allow(ENV).to receive(:[]).with('DOCKER_URL').and_return(nil)
12
- allow(ENV).to receive(:[]).with('DOCKER_HOST').and_return(nil)
13
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH').and_return(nil)
14
- Docker.reset!
15
- end
16
- after { Docker.reset! }
17
-
18
- its(:options) { should == {} }
19
- its(:url) { should == 'unix:///var/run/docker.sock' }
20
- its(:connection) { should be_a Docker::Connection }
21
- end
22
-
23
- context "when the DOCKER_* ENV variables are set" do
24
- before do
25
- allow(ENV).to receive(:[]).with('DOCKER_URL')
26
- .and_return('unixs:///var/run/not-docker.sock')
27
- allow(ENV).to receive(:[]).with('DOCKER_HOST').and_return(nil)
28
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH').and_return(nil)
29
- Docker.reset!
30
- end
31
- after { Docker.reset! }
32
-
33
- its(:options) { should == {} }
34
- its(:url) { should == 'unixs:///var/run/not-docker.sock' }
35
- its(:connection) { should be_a Docker::Connection }
36
- end
37
-
38
- context "when the DOCKER_HOST is set and uses default tcp://" do
39
- before do
40
- allow(ENV).to receive(:[]).with('DOCKER_URL').and_return(nil)
41
- allow(ENV).to receive(:[]).with('DOCKER_HOST').and_return('tcp://')
42
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH').and_return(nil)
43
- Docker.reset!
44
- end
45
- after { Docker.reset! }
46
-
47
- its(:options) { should == {} }
48
- its(:url) { should == 'tcp://localhost:2375' }
49
- its(:connection) { should be_a Docker::Connection }
50
- end
51
-
52
- context "when the DOCKER_HOST ENV variable is set" do
53
- before do
54
- allow(ENV).to receive(:[]).with('DOCKER_URL').and_return(nil)
55
- allow(ENV).to receive(:[]).with('DOCKER_HOST')
56
- .and_return('tcp://someserver:8103')
57
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH').and_return(nil)
58
- Docker.reset!
59
- end
60
- after { Docker.reset! }
61
-
62
- its(:options) { should == {} }
63
- its(:url) { should == 'tcp://someserver:8103' }
64
- its(:connection) { should be_a Docker::Connection }
65
- end
66
-
67
- context "DOCKER_URL should take precedence over DOCKER_HOST" do
68
- before do
69
- allow(ENV).to receive(:[]).with('DOCKER_URL')
70
- .and_return('tcp://someotherserver:8103')
71
- allow(ENV).to receive(:[]).with('DOCKER_HOST')
72
- .and_return('tcp://someserver:8103')
73
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH').and_return(nil)
74
- Docker.reset!
75
- end
76
- after { Docker.reset! }
77
-
78
- its(:options) { should == {} }
79
- its(:url) { should == 'tcp://someotherserver:8103' }
80
- its(:connection) { should be_a Docker::Connection }
81
- end
82
-
83
- context "when the DOCKER_CERT_PATH and DOCKER_HOST ENV variables are set" do
84
- before do
85
- allow(ENV).to receive(:[]).with('DOCKER_URL').and_return(nil)
86
- allow(ENV).to receive(:[]).with('DOCKER_HOST')
87
- .and_return('tcp://someserver:8103')
88
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH')
89
- .and_return('/boot2dockert/cert/path')
90
- allow(ENV).to receive(:[]).with('DOCKER_SSL_VERIFY').and_return(nil)
91
- Docker.reset!
92
- end
93
- after { Docker.reset! }
94
-
95
- its(:options) {
96
- should == {
97
- client_cert: '/boot2dockert/cert/path/cert.pem',
98
- client_key: '/boot2dockert/cert/path/key.pem',
99
- ssl_ca_file: '/boot2dockert/cert/path/ca.pem',
100
- scheme: 'https'
101
- }
102
- }
103
- its(:url) { should == 'tcp://someserver:8103' }
104
- its(:connection) { should be_a Docker::Connection }
105
- end
106
-
107
- context "when the DOCKER_CERT_PATH and DOCKER_SSL_VERIFY ENV variables are set" do
108
- before do
109
- allow(ENV).to receive(:[]).with('DOCKER_URL').and_return(nil)
110
- allow(ENV).to receive(:[]).with('DOCKER_HOST')
111
- .and_return('tcp://someserver:8103')
112
- allow(ENV).to receive(:[]).with('DOCKER_CERT_PATH')
113
- .and_return('/boot2dockert/cert/path')
114
- allow(ENV).to receive(:[]).with('DOCKER_SSL_VERIFY')
115
- .and_return('false')
116
- Docker.reset!
117
- end
118
- after { Docker.reset! }
119
-
120
- its(:options) {
121
- should == {
122
- client_cert: '/boot2dockert/cert/path/cert.pem',
123
- client_key: '/boot2dockert/cert/path/key.pem',
124
- ssl_ca_file: '/boot2dockert/cert/path/ca.pem',
125
- scheme: 'https',
126
- ssl_verify_peer: false
127
- }
128
- }
129
- its(:url) { should == 'tcp://someserver:8103' }
130
- its(:connection) { should be_a Docker::Connection }
131
- end
132
-
133
- end
134
-
135
- describe '#reset_connection!' do
136
- before { subject.connection }
137
- it 'sets the @connection to nil' do
138
- expect { subject.reset_connection! }
139
- .to change { subject.instance_variable_get(:@connection) }
140
- .to nil
141
- end
142
- end
143
-
144
- [:options=, :url=].each do |method|
145
- describe "##{method}" do
146
- before { Docker.reset! }
147
-
148
- it 'calls #reset_connection!' do
149
- expect(subject).to receive(:reset_connection!)
150
- subject.public_send(method, nil)
151
- end
152
- end
153
- end
154
-
155
- describe '#version' do
156
- before { Docker.reset! }
157
-
158
- let(:expected) {
159
- %w[ApiVersion Arch GitCommit GoVersion KernelVersion Os Version]
160
- }
161
-
162
- let(:version) { subject.version }
163
- it 'returns the version as a Hash' do
164
- expect(version).to be_a Hash
165
- expect(version.keys.sort).to include(*expected)
166
- end
167
- end
168
-
169
- describe '#info' do
170
- before { Docker.reset! }
171
-
172
- let(:info) { subject.info }
173
- let(:keys) do
174
- %w(Containers Debug DockerRootDir Driver DriverStatus ExecutionDriver ID
175
- IPv4Forwarding Images IndexServerAddress InitPath InitSha1
176
- KernelVersion Labels MemTotal MemoryLimit NCPU NEventsListener NFd
177
- NGoroutines Name OperatingSystem SwapLimit)
178
- end
179
-
180
- it 'returns the info as a Hash' do
181
- expect(info).to be_a Hash
182
- expect(info.keys.sort).to include(*keys)
183
- end
184
- end
185
-
186
- describe '#ping' do
187
- before { Docker.reset! }
188
-
189
- let(:ping) { subject.ping}
190
-
191
- it 'returns the status as a String' do
192
- expect(ping).to eq('OK')
193
- end
194
- end
195
-
196
- describe '#authenticate!' do
197
- subject { described_class }
198
-
199
- let(:authentication) {
200
- subject.authenticate!(credentials)
201
- }
202
-
203
- after { Docker.creds = nil }
204
-
205
- context 'with valid credentials' do
206
- let(:credentials) {
207
- {
208
- :username => ENV['DOCKER_API_USER'],
209
- :password => ENV['DOCKER_API_PASS'],
210
- :email => ENV['DOCKER_API_EMAIL'],
211
- :serveraddress => 'https://index.docker.io/v1/'
212
- }
213
- }
214
-
215
- it 'logs in and sets the creds' do
216
- expect(authentication).to be true
217
- expect(Docker.creds).to eq(credentials.to_json)
218
- end
219
- end
220
-
221
- context 'with invalid credentials' do
222
- let(:credentials) {
223
- {
224
- :username => 'test',
225
- :password => 'password',
226
- :email => 'test@example.com',
227
- :serveraddress => 'https://index.docker.io/v1/'
228
- }
229
- }
230
-
231
- it "raises an error and doesn't set the creds" do
232
- expect {
233
- authentication
234
- }.to raise_error(Docker::Error::AuthenticationError)
235
- expect(Docker.creds).to be_nil
236
- end
237
- end
238
- end
239
-
240
- describe '#validate_version' do
241
- before { Docker.reset! }
242
-
243
- context 'when a Docker Error is raised' do
244
- before do
245
- allow(Docker).to receive(:info).and_raise(Docker::Error::ClientError)
246
- end
247
-
248
- it 'raises a Version Error' do
249
- expect { subject.validate_version! }
250
- .to raise_error(Docker::Error::VersionError)
251
- end
252
- end
253
-
254
- context 'when nothing is raised' do
255
- its(:validate_version!) { should be true }
256
- end
257
- end
258
- end
@@ -1,2 +0,0 @@
1
- FROM debian:wheezy
2
- ADD . /
Binary file
Binary file
@@ -1,2 +0,0 @@
1
- FROM debian:wheezy
2
- RUN printf '#! /bin/sh\nwhile true\ndo\ntrue\ndone\n' > /while && chmod +x /while
@@ -1,36 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
-
3
- require 'rspec'
4
- require 'rspec/its'
5
- require 'simplecov'
6
- require 'docker'
7
-
8
- ENV['DOCKER_API_USER'] ||= 'debbie_docker'
9
- ENV['DOCKER_API_PASS'] ||= '*************'
10
- ENV['DOCKER_API_EMAIL'] ||= 'debbie_docker@example.com'
11
-
12
- RSpec.shared_context "local paths" do
13
- def project_dir
14
- File.expand_path(File.join(File.dirname(__FILE__), '..'))
15
- end
16
- end
17
-
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
19
-
20
- RSpec.configure do |config|
21
- config.mock_with :rspec
22
- config.color = true
23
- config.formatter = :documentation
24
- config.tty = true
25
-
26
- case ENV['DOCKER_VERSION']
27
- when /1\.6/
28
- config.filter_run_excluding :docker_1_8 => true
29
- config.filter_run_excluding :docker_1_9 => true
30
- when /1\.7/
31
- config.filter_run_excluding :docker_1_8 => true
32
- config.filter_run_excluding :docker_1_9 => true
33
- when /1\.8/
34
- config.filter_run_excluding :docker_1_9 => true
35
- end
36
- end