vagrant-proxyconf 1.5.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -14
  4. data/CHANGELOG.md +19 -0
  5. data/Gemfile +25 -7
  6. data/LICENSE.txt +1 -1
  7. data/README.md +117 -18
  8. data/Rakefile +1 -27
  9. data/development/Dockerfile +40 -0
  10. data/development/README.md +2 -0
  11. data/development/Vagrantfile.example +156 -9
  12. data/development/install-c7.sh +46 -0
  13. data/development/install-debian.sh +55 -0
  14. data/development/tinyproxy.conf +333 -0
  15. data/lib/vagrant-proxyconf/action.rb +15 -7
  16. data/lib/vagrant-proxyconf/action/base.rb +47 -5
  17. data/lib/vagrant-proxyconf/action/configure_apt_proxy.rb +17 -0
  18. data/lib/vagrant-proxyconf/action/configure_chef_proxy.rb +32 -27
  19. data/lib/vagrant-proxyconf/action/configure_docker_proxy.rb +113 -12
  20. data/lib/vagrant-proxyconf/action/configure_env_proxy.rb +58 -11
  21. data/lib/vagrant-proxyconf/action/configure_git_proxy.rb +25 -9
  22. data/lib/vagrant-proxyconf/action/configure_npm_proxy.rb +14 -6
  23. data/lib/vagrant-proxyconf/action/configure_pear_proxy.rb +15 -8
  24. data/lib/vagrant-proxyconf/action/configure_svn_proxy.rb +15 -8
  25. data/lib/vagrant-proxyconf/action/configure_yum_proxy.rb +16 -0
  26. data/lib/vagrant-proxyconf/cap/linux/chef_proxy_conf.rb +17 -0
  27. data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
  28. data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
  29. data/lib/vagrant-proxyconf/cap/util.rb +4 -5
  30. data/lib/vagrant-proxyconf/capability.rb +10 -0
  31. data/lib/vagrant-proxyconf/config.rb +20 -0
  32. data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
  33. data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
  34. data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
  35. data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
  36. data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
  37. data/lib/vagrant-proxyconf/version.rb +1 -1
  38. data/locales/en.yml +38 -0
  39. data/resources/yum_config.awk +1 -0
  40. data/spec/spec_helper.rb +27 -9
  41. data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
  42. data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
  43. data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
  44. data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
  45. data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
  46. data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
  47. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
  48. data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +489 -0
  49. data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
  50. data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
  51. data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
  52. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
  53. data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
  54. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
  55. data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
  56. data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
  57. data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
  58. data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
  59. data/travis/before_install +26 -0
  60. metadata +24 -4
@@ -7,9 +7,14 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureChefProxy do
7
7
  describe '#configure_chef' do
8
8
  let(:chef) { OpenStruct.new }
9
9
  let(:config) { OpenStruct.new }
10
+ let(:machine) { double('machine') }
11
+
10
12
 
11
13
  def configure_chef
12
14
  action = described_class.new(nil, nil)
15
+ action.instance_variable_set(:@machine, machine)
16
+ config.enabled = true if config.enabled.nil?
17
+ allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
13
18
  allow(action).to receive(:config) { config }
14
19
  action.send(:configure_chef, chef)
15
20
  end
@@ -85,6 +90,33 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureChefProxy do
85
90
  expect(chef.https_proxy).to eq 'http://sslproxy:3128'
86
91
  end
87
92
  end
93
+
94
+ context 'when user wants to disable the configured chef proxy and does not unset the configured proxy variables' do
95
+ before :each do
96
+ config.enabled = false
97
+ config.http = 'http://username:secretpass@my-proxy-host.example.com:8080'
98
+ config.https = 'https://username:secretpass@my-proxy-host.example.com:8080'
99
+ config.no_proxy = 'localhost,*.example.com'
100
+
101
+ configure_chef
102
+ end
103
+
104
+ it 'should unconfigure chef proxy' do
105
+ expect(config.enabled).to eq false
106
+ expect(config.http).to eq 'http://username:secretpass@my-proxy-host.example.com:8080'
107
+ expect(config.https).to eq 'https://username:secretpass@my-proxy-host.example.com:8080'
108
+ expect(config.no_proxy).to eq 'localhost,*.example.com'
109
+
110
+ expect(chef.http_proxy).to be_nil
111
+ expect(chef.http_proxy_user).to be_nil
112
+ expect(chef.http_proxy_pass).to be_nil
113
+ expect(chef.https_proxy).to be_nil
114
+ expect(chef.https_proxy_user).to be_nil
115
+ expect(chef.https_proxy_pass).to be_nil
116
+ expect(chef.no_proxy).to be_nil
117
+ end
118
+ end
119
+
88
120
  end
89
121
 
90
122
  end
@@ -1,10 +1,499 @@
1
1
  require 'spec_helper'
2
+ require 'vagrant-proxyconf/config/proxy'
2
3
  require 'vagrant-proxyconf/action/configure_docker_proxy'
3
4
 
5
+ def mock_write_docker_config(machine)
6
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf", error_check: false)
7
+ allow(machine).to receive_message_chain(:communicate, :upload)
8
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("touch /etc/default/docker")
9
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -e '/^HTTP_PROXY=/ d\n/^http_proxy=/ d\n/^HTTPS_PROXY=/ d\n/^https_proxy=/ d\n/^NO_PROXY=/ d\n/^no_proxy=/ d\n' /etc/default/docker > /etc/default/docker.new")
10
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("cat /tmp/vagrant-proxyconf >> /etc/default/docker.new")
11
+ allow(machine).to receive_message_chain(:communicate, :test).with("diff /etc/default/docker.new /etc/default/docker")
12
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/default/docker.new")
13
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/default/docker.new")
14
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /etc/default/docker.new /etc/default/docker")
15
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("systemctl restart docker || service docker restart || /etc/init.d/docker restart")
16
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf /etc/default/docker.new")
17
+ end
18
+
19
+ def mock_update_docker_client_config(machine, config_path)
20
+ allow(machine).to receive_message_chain(:communicate, :upload).with(config_path, config_path)
21
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mv #{config_path} /etc/docker/config.json")
22
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/docker/config.json")
23
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f #{config_path}")
24
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -i.bak -e '/^DOCKER_CONFIG/d' /etc/environment")
25
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("echo DOCKER_CONFIG=/etc/docker >> /etc/environment")
26
+ end
27
+
28
+
4
29
  describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
5
30
 
6
31
  describe '#config_name' do
7
32
  subject { described_class.new(double, double).config_name }
8
33
  it { is_expected.to eq 'docker_proxy' }
9
34
  end
35
+
36
+ describe "#configure_machine" do
37
+
38
+ context 'when docker is not supported' do
39
+ let(:app) { OpenStruct.new }
40
+ let(:env) { OpenStruct.new }
41
+ let(:machine) { double('machine') }
42
+
43
+ def configure_docker_proxy
44
+ docker_proxy = described_class.new(app, env)
45
+ docker_proxy.instance_variable_set(:@machine, machine)
46
+
47
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
48
+
49
+ @docker_proxy = docker_proxy
50
+ end
51
+
52
+ before :each do
53
+ configure_docker_proxy
54
+ end
55
+
56
+ it 'return nil' do
57
+ expect(@docker_proxy.send(:configure_machine)).to be_nil
58
+ end
59
+ end
60
+
61
+ context "when docker is supported" do
62
+ let(:app) { OpenStruct.new }
63
+ let(:env) { OpenStruct.new }
64
+ let(:machine) { double('machine') }
65
+
66
+ def configure_docker_proxy(fixture)
67
+ docker_proxy = described_class.new(app, env)
68
+ docker_proxy.instance_variable_set(:@machine, machine)
69
+
70
+ # #docker_client_config_path mock
71
+ fixture = docker_proxy.send(:tempfile, load_fixture(fixture)).path
72
+ docker_proxy.instance_variable_set(:@docker_client_config_path, fixture)
73
+
74
+ # #supported? mock
75
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
76
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
77
+
78
+ # #config mock
79
+ config = create_config_proxy(
80
+ :enabled => true,
81
+ :http => 'http://proxy-server-01.example.com:8080',
82
+ :https => 'https://proxy-server-01.example.com:8080',
83
+ :no_proxy => 'localhost',
84
+ )
85
+
86
+ allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
87
+ allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
88
+
89
+ mock_write_docker_config(machine)
90
+ mock_update_docker_client_config(machine, fixture)
91
+
92
+ # update_docker_client_config mock
93
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
94
+
95
+ @docker_proxy = docker_proxy
96
+ end
97
+
98
+ context 'when /etc/docker/config.json has proxy configuration' do
99
+ before :each do
100
+ fixture = fixture_file("docker_client_config_json_enabled_proxy")
101
+ configure_docker_proxy(fixture)
102
+ end
103
+
104
+ it 'update /etc/docker/config.json' do
105
+ allow(machine).to receive_message_chain(:communicate, :test).with('command -v systemctl').and_return('')
106
+
107
+ expect(@docker_proxy.send(:configure_machine)).to eq true
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "#docker_client_config_path" do
114
+ let(:machine) { double('machine') }
115
+
116
+ context "when not supported" do
117
+ subject do
118
+ docker_proxy = described_class.new(nil, nil)
119
+ docker_proxy.instance_variable_set(:@machine, machine)
120
+
121
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(false)
122
+
123
+ # #supported? mock
124
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
125
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
126
+
127
+ docker_proxy.send(:docker_client_config_path)
128
+ end
129
+
130
+ it { is_expected.to eq nil }
131
+ end
132
+
133
+ context "when supported" do
134
+ context "when /etc/docker/config.json exists" do
135
+ subject do
136
+ docker_proxy = described_class.new(nil, nil)
137
+ docker_proxy.instance_variable_set(:@machine, machine)
138
+ docker_proxy.instance_variable_set(:@docker_client_config_path, nil)
139
+
140
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
141
+
142
+ allow(machine).to receive_message_chain(:communicate, :test).with("[ -f /etc/docker/config.json ]").and_return(true)
143
+ allow(machine).to receive_message_chain(:communicate, :download).with("/etc/docker/config.json", "/tmp/vagrant-proxyconf-docker-config.json")
144
+
145
+ docker_proxy.send(:docker_client_config_path)
146
+ end
147
+
148
+ it { is_expected.to eq "/tmp/vagrant-proxyconf-docker-config.json" }
149
+ end
150
+
151
+ context "when /etc/docker/config.json does not exist" do
152
+ subject do
153
+ docker_proxy = described_class.new(nil, nil)
154
+ docker_proxy.instance_variable_set(:@machine, machine)
155
+ docker_proxy.instance_variable_set(:@docker_client_config_path, nil)
156
+
157
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
158
+
159
+ allow(machine).to receive_message_chain(:communicate, :test).with("[ -f /etc/docker/config.json ]").and_return(false)
160
+
161
+ docker_proxy.send(:docker_client_config_path)
162
+ end
163
+
164
+ it { is_expected.to eq "/tmp/vagrant-proxyconf-docker-config.json" }
165
+ it do
166
+ expect(File.exists?("/tmp/vagrant-proxyconf-docker-config.json")).to eq true
167
+ expect(File.read("/tmp/vagrant-proxyconf-docker-config.json")).to eq "{}"
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ describe "#update_docker_client_config" do
174
+ let(:app) { OpenStruct.new }
175
+ let(:env) { OpenStruct.new }
176
+ let(:machine) { double('machine') }
177
+
178
+ context "when #supports_config_json? returns false" do
179
+
180
+ it 'return nil' do
181
+ docker_proxy = described_class.new(app, env)
182
+ docker_proxy.instance_variable_set(:@machine, machine)
183
+
184
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(false)
185
+
186
+ # #supported? mock
187
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
188
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
189
+
190
+ expect(docker_proxy.send(:update_docker_client_config)).to eq nil
191
+ end
192
+
193
+ end
194
+
195
+ context "when #docker_client_config_path returns nil" do
196
+ it 'return nil' do
197
+ docker_proxy = described_class.new(app, env)
198
+ docker_proxy.instance_variable_set(:@machine, machine)
199
+
200
+ # mock a result that looks like no proxy is configured for the config.json
201
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
202
+ allow(docker_proxy).to receive(:docker_client_config_path).and_return(nil)
203
+
204
+ # #supported? mock
205
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
206
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
207
+
208
+ expect(docker_proxy.send(:update_docker_client_config)).to eq nil
209
+ end
210
+ end
211
+
212
+ context "when /etc/docker/config.json is supported" do
213
+
214
+ context "when configuration is disabled" do
215
+ it do
216
+ docker_proxy = described_class.new(app, env)
217
+ docker_proxy.instance_variable_set(:@machine, machine)
218
+
219
+ # mock a result that looks like proxy is configured for the config.json
220
+ fixture = fixture_file("docker_client_config_json_enabled_proxy")
221
+ fixture_content = load_fixture(fixture)
222
+ config_path = docker_proxy.send(:tempfile, fixture_content).path
223
+
224
+ docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
225
+
226
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
227
+ allow(docker_proxy).to receive(:disabled?).and_return(true)
228
+
229
+ mock_update_docker_client_config(machine, config_path)
230
+
231
+ expected = JSON.pretty_generate(
232
+ {
233
+ "proxies" => {
234
+ "default" => Hash.new
235
+ }
236
+ }
237
+ )
238
+ expect(docker_proxy.send(:update_docker_client_config)).to eq expected
239
+ end
240
+ end
241
+
242
+ context "when configuration is enabled" do
243
+ it do
244
+ docker_proxy = described_class.new(app, env)
245
+ docker_proxy.instance_variable_set(:@machine, machine)
246
+
247
+ # simulate config
248
+ config = create_config_proxy(
249
+ :enabled => true,
250
+ :http => 'http://proxy-server-01.example.com:8080',
251
+ :https => 'https://proxy-server-01.example.com:8080',
252
+ :no_proxy => 'localhost',
253
+ )
254
+
255
+ allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
256
+ allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
257
+
258
+ # mock a result that looks like no proxy is configured for the config.json
259
+ fixture = fixture_file("docker_client_config_json_no_proxy")
260
+ fixture_content = load_fixture(fixture)
261
+ config_path = docker_proxy.send(:tempfile, fixture_content).path
262
+
263
+ docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
264
+
265
+ allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
266
+ allow(docker_proxy).to receive(:disabled?).and_return(false)
267
+
268
+ mock_update_docker_client_config(machine, config_path)
269
+ expected = JSON.pretty_generate(
270
+ {
271
+ "proxies" => {
272
+ "default" => {
273
+ "httpProxy" => "http://proxy-server-01.example.com:8080",
274
+ "httpsProxy" => "https://proxy-server-01.example.com:8080",
275
+ "noProxy" => "localhost",
276
+ }
277
+ }
278
+ }
279
+ )
280
+
281
+ expect(docker_proxy.send(:update_docker_client_config)).to eq expected
282
+ end
283
+ end
284
+ end
285
+ end
286
+
287
+ describe "#unconfigure_machine" do
288
+
289
+ context "when not supported" do
290
+ let(:app) { OpenStruct.new }
291
+ let(:env) { OpenStruct.new }
292
+ let(:machine) { double('machine') }
293
+
294
+ subject do
295
+ docker_proxy = described_class.new(app, env)
296
+ docker_proxy.instance_variable_set(:@machine, machine)
297
+
298
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
299
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
300
+
301
+ docker_proxy.send(:unconfigure_machine)
302
+ end
303
+
304
+ it 'return nil' do
305
+ is_expected.to eq nil
306
+ end
307
+ end
308
+
309
+ context "when supported" do
310
+ context "when config is enabled" do
311
+ let(:app) { OpenStruct.new }
312
+ let(:env) { OpenStruct.new }
313
+ let(:machine) { double('machine') }
314
+
315
+ subject do
316
+ docker_proxy = described_class.new(app, env)
317
+ docker_proxy.instance_variable_set(:@machine, machine)
318
+ docker_proxy.instance_variable_set(:@version, [18, 9, 0])
319
+
320
+ fixture = fixture_file("docker_client_config_json_enabled_proxy")
321
+ config_path = docker_proxy.send(:tempfile, load_fixture(fixture)).path
322
+ docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
323
+
324
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
325
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
326
+
327
+ # #config mock
328
+ allow(machine).to receive_message_chain(:config, :proxy, :enabled).and_return(true)
329
+ config = create_config_proxy(
330
+ :enabled => true,
331
+ :http => 'http://proxy-server-01.example.com:8080',
332
+ :https => 'https://proxy-server-01.example.com:8080',
333
+ :no_proxy => 'localhost',
334
+ )
335
+ allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
336
+ allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
337
+
338
+ # mock write_docker_config
339
+ mock_write_docker_config(machine)
340
+
341
+ # mock update_docker_client_config
342
+ mock_update_docker_client_config(machine, config_path)
343
+
344
+ docker_proxy.send(:unconfigure_machine)
345
+ end
346
+
347
+ it 'return true' do
348
+ is_expected.to eq true
349
+ end
350
+ end
351
+
352
+ context "when config is disabled" do
353
+ let(:app) { OpenStruct.new }
354
+ let(:env) { OpenStruct.new }
355
+ let(:machine) { double('machine') }
356
+
357
+ subject do
358
+ docker_proxy = described_class.new(app, env)
359
+ docker_proxy.instance_variable_set(:@machine, machine)
360
+ docker_proxy.instance_variable_set(:@version, [18, 9, 0])
361
+
362
+ fixture = fixture_file("docker_client_config_json_enabled_proxy")
363
+ config_path = docker_proxy.send(:tempfile, load_fixture(fixture)).path
364
+ docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
365
+
366
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
367
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
368
+
369
+ # #config mock
370
+ allow(machine).to receive_message_chain(:config, :proxy, :enabled?).and_return(false)
371
+ config = create_config_proxy(
372
+ :enabled => false,
373
+ :http => 'http://proxy-server-01.example.com:8080',
374
+ :https => 'https://proxy-server-01.example.com:8080',
375
+ :no_proxy => 'localhost',
376
+ )
377
+ allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
378
+ allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
379
+
380
+ allow(docker_proxy).to receive(:disabled?).and_return(true)
381
+
382
+ mock_write_docker_config(machine)
383
+ mock_update_docker_client_config(machine, config_path)
384
+
385
+ docker_proxy.send(:unconfigure_machine)
386
+ end
387
+
388
+ it 'should disable proxy configuration' do
389
+ is_expected.to eq true
390
+ end
391
+ end
392
+
393
+ end
394
+ end
395
+
396
+ describe "#docker_version" do
397
+ let(:machine) { double('machine') }
398
+
399
+ context "when not supported" do
400
+ subject do
401
+ docker_proxy = described_class.new(nil, nil)
402
+ docker_proxy.instance_variable_set(:@machine, machine)
403
+
404
+ # #supported? mock
405
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
406
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
407
+
408
+ docker_proxy.send(:docker_version)
409
+ end
410
+
411
+ it { is_expected.to eq nil }
412
+ end
413
+
414
+ context "when supported parse" do
415
+ subject do
416
+ docker_proxy = described_class.new(nil, nil)
417
+ docker_proxy.instance_variable_set(:@machine, machine)
418
+
419
+ # #supported? mock
420
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
421
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return("/etc/default/docker")
422
+
423
+ allow(machine).to receive_message_chain(:communicate, :execute).with('docker --version').and_yield(@type, @version)
424
+
425
+ docker_proxy.send(:docker_version)
426
+ end
427
+
428
+ context '"Docker version 17.05.0-ce, build 89658be"' do
429
+ it do
430
+ @type = :stdout
431
+ @version = "Docker version 17.05.0-ce, build 89658be"
432
+
433
+ is_expected.to eq [17, 5, 0]
434
+ end
435
+ end
436
+
437
+ context '"Docker version 18.09.0, build 4d60db4"' do
438
+ it do
439
+ @type = :stdout
440
+ @version = "Docker version 18.09.0, build 4d60db4"
441
+
442
+ is_expected.to eq [18, 9, 0]
443
+ end
444
+ end
445
+ end
446
+ end
447
+
448
+ describe "#supports_config_json?" do
449
+ let(:machine) { double('machine') }
450
+
451
+ context "when not supported" do
452
+ subject do
453
+ docker_proxy = described_class.new(nil, nil)
454
+ docker_proxy.instance_variable_set(:@machine, machine)
455
+
456
+ # #supported? mock
457
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
458
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
459
+
460
+ docker_proxy.send(:supports_config_json?)
461
+ end
462
+
463
+ it 'returns false' do
464
+ is_expected.to eq false
465
+ end
466
+ end
467
+
468
+ context "when supported" do
469
+ subject do
470
+ docker_proxy = described_class.new(nil, nil)
471
+ docker_proxy.instance_variable_set(:@machine, machine)
472
+ docker_proxy.instance_variable_set(:@version, @version)
473
+
474
+ # #supported? mock
475
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
476
+ allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return("/etc/defualt/docker")
477
+
478
+ docker_proxy.send(:supports_config_json?)
479
+ end
480
+
481
+ it 'given docker_version is 18.09.1, return true' do
482
+ @version = [18, 9, 1]
483
+ is_expected.to eq true
484
+ end
485
+
486
+ it 'given docker_version is 17.07, return true' do
487
+ @version = [17, 7, 0]
488
+ is_expected.to eq true
489
+ end
490
+
491
+ it 'given docker_version is 17.06, return false' do
492
+ @version = [17, 6, 0]
493
+ is_expected.to eq false
494
+ end
495
+ end
496
+
497
+ end
498
+
10
499
  end