beaker-vagrant 0.7.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,414 +3,412 @@ require 'spec_helper'
3
3
 
4
4
  module Beaker
5
5
  describe Vagrant do
6
-
7
- let( :options ) {
6
+ let(:options) do
8
7
  make_opts.merge({
9
- 'logger' => double().as_null_object,
10
- :hosts_file => 'sample.cfg',
11
- :forward_ssh_agent => true,
12
- })
13
- }
8
+ 'logger' => double.as_null_object,
9
+ :hosts_file => 'sample.cfg',
10
+ :forward_ssh_agent => true,
11
+ })
12
+ end
14
13
 
15
- let( :vagrant ) { Beaker::Vagrant.new( @hosts, options ) }
14
+ let(:vagrant) { Beaker::Vagrant.new(@hosts, options) }
16
15
 
17
16
  before :each do
18
17
  @hosts = make_hosts({
19
- :mount_folders => {
20
- :test_temp => {:from => './', :to => '/temp'},
21
- :test_tmp => {:from => '../', :to => '/tmp'}
22
- },
23
- :forwarded_ports => {
24
- :http => {:from => 10080, :to => 80},
25
- :ssl => {:from => 4443, :to => 443},
26
- :tomcat => {:from => 8080, :to => 8080}
27
- },
28
- :platform => Beaker::Platform.new('centos-8-x86_64')
29
- })
18
+ mount_folders: {
19
+ test_temp: { from: './', to: '/temp' },
20
+ test_tmp: { from: '../', to: '/tmp' }
21
+ },
22
+ forwarded_ports: {
23
+ http: { from: 10_080, to: 80 },
24
+ ssl: { from: 4443, to: 443 },
25
+ tomcat: { from: 8080, to: 8080 }
26
+ },
27
+ platform: Beaker::Platform.new('centos-8-x86_64')
28
+ })
30
29
  end
31
30
 
32
- it "stores the vagrant file in $WORKINGDIR/.vagrant/beaker_vagrant_files/beaker_sample.cfg" do
33
- path = vagrant.instance_variable_get( :@vagrant_path )
34
-
35
- expect( path ).to be === File.join(Dir.pwd, '.vagrant', 'beaker_vagrant_files', 'beaker_sample.cfg')
31
+ it 'stores the vagrant file in $WORKINGDIR/.vagrant/beaker_vagrant_files/beaker_sample.cfg' do
32
+ path = vagrant.instance_variable_get(:@vagrant_path)
36
33
 
34
+ expect(path).to be === File.join(Dir.pwd, '.vagrant', 'beaker_vagrant_files', 'beaker_sample.cfg')
37
35
  end
38
36
 
39
- it "can make a Vagrantfile for a set of hosts" do
40
- path = vagrant.instance_variable_get( :@vagrant_path )
37
+ it 'can make a Vagrantfile for a set of hosts' do
38
+ path = vagrant.instance_variable_get(:@vagrant_path)
41
39
 
42
- vagrant.make_vfile( @hosts )
40
+ vagrant.make_vfile(@hosts)
43
41
 
44
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
42
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
45
43
  puts "file is #{path}\n"
46
- expect( vagrantfile ).to be === <<-EOF
47
- Vagrant.configure("2") do |c|
48
- c.ssh.insert_key = false
49
- c.vm.define 'vm1' do |v|
50
- v.vm.hostname = 'vm1'
51
- v.vm.box = 'vm2vm1_of_my_box'
52
- v.vm.box_url = 'http://address.for.my.box.vm1'
53
- v.vm.box_check_update = 'true'
54
- v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"
55
- v.vm.synced_folder './', '/temp', create: true
56
- v.vm.synced_folder '../', '/tmp', create: true
57
- v.vm.network :forwarded_port, guest: 80, host: 10080
58
- v.vm.network :forwarded_port, guest: 443, host: 4443
59
- v.vm.network :forwarded_port, guest: 8080, host: 8080
60
- v.vm.provider :virtualbox do |vb|
61
- vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
62
- end
63
- end
64
- c.vm.define 'vm2' do |v|
65
- v.vm.hostname = 'vm2'
66
- v.vm.box = 'vm2vm2_of_my_box'
67
- v.vm.box_url = 'http://address.for.my.box.vm2'
68
- v.vm.box_check_update = 'true'
69
- v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0"
70
- v.vm.synced_folder './', '/temp', create: true
71
- v.vm.synced_folder '../', '/tmp', create: true
72
- v.vm.network :forwarded_port, guest: 80, host: 10080
73
- v.vm.network :forwarded_port, guest: 443, host: 4443
74
- v.vm.network :forwarded_port, guest: 8080, host: 8080
75
- v.vm.provider :virtualbox do |vb|
76
- vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
77
- end
78
- end
79
- c.vm.define 'vm3' do |v|
80
- v.vm.hostname = 'vm3'
81
- v.vm.box = 'vm2vm3_of_my_box'
82
- v.vm.box_url = 'http://address.for.my.box.vm3'
83
- v.vm.box_check_update = 'true'
84
- v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0"
85
- v.vm.synced_folder './', '/temp', create: true
86
- v.vm.synced_folder '../', '/tmp', create: true
87
- v.vm.network :forwarded_port, guest: 80, host: 10080
88
- v.vm.network :forwarded_port, guest: 443, host: 4443
89
- v.vm.network :forwarded_port, guest: 8080, host: 8080
90
- v.vm.provider :virtualbox do |vb|
91
- vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
92
- end
93
- end
94
- end
95
- EOF
44
+ expect(vagrantfile).to be === <<~EOF
45
+ Vagrant.configure("2") do |c|
46
+ c.ssh.insert_key = false
47
+ c.vm.define 'vm1' do |v|
48
+ v.vm.hostname = 'vm1'
49
+ v.vm.box = 'vm2vm1_of_my_box'
50
+ v.vm.box_url = 'http://address.for.my.box.vm1'
51
+ v.vm.box_check_update = 'true'
52
+ v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"
53
+ v.vm.synced_folder './', '/temp', create: true
54
+ v.vm.synced_folder '../', '/tmp', create: true
55
+ v.vm.network :forwarded_port, guest: 80, host: 10080
56
+ v.vm.network :forwarded_port, guest: 443, host: 4443
57
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
58
+ v.vm.provider :virtualbox do |vb|
59
+ vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
60
+ end
61
+ end
62
+ c.vm.define 'vm2' do |v|
63
+ v.vm.hostname = 'vm2'
64
+ v.vm.box = 'vm2vm2_of_my_box'
65
+ v.vm.box_url = 'http://address.for.my.box.vm2'
66
+ v.vm.box_check_update = 'true'
67
+ v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0"
68
+ v.vm.synced_folder './', '/temp', create: true
69
+ v.vm.synced_folder '../', '/tmp', create: true
70
+ v.vm.network :forwarded_port, guest: 80, host: 10080
71
+ v.vm.network :forwarded_port, guest: 443, host: 4443
72
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
73
+ v.vm.provider :virtualbox do |vb|
74
+ vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
75
+ end
76
+ end
77
+ c.vm.define 'vm3' do |v|
78
+ v.vm.hostname = 'vm3'
79
+ v.vm.box = 'vm2vm3_of_my_box'
80
+ v.vm.box_url = 'http://address.for.my.box.vm3'
81
+ v.vm.box_check_update = 'true'
82
+ v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0"
83
+ v.vm.synced_folder './', '/temp', create: true
84
+ v.vm.synced_folder '../', '/tmp', create: true
85
+ v.vm.network :forwarded_port, guest: 80, host: 10080
86
+ v.vm.network :forwarded_port, guest: 443, host: 4443
87
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
88
+ v.vm.provider :virtualbox do |vb|
89
+ vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
90
+ end
91
+ end
92
+ end
93
+ EOF
96
94
  end
97
95
 
98
- it "can make a Vagrantfile with ssh agent forwarding enabled" do
99
- path = vagrant.instance_variable_get( :@vagrant_path )
96
+ it 'can make a Vagrantfile with ssh agent forwarding enabled' do
97
+ path = vagrant.instance_variable_get(:@vagrant_path)
100
98
 
101
- hosts = make_hosts({},1)
102
- vagrant.make_vfile( hosts, options )
99
+ hosts = make_hosts({}, 1)
100
+ vagrant.make_vfile(hosts, options)
103
101
 
104
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
105
- expect( vagrantfile ).to match(/(ssh.forward_agent = true)/)
102
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
103
+ expect(vagrantfile).to match(/(ssh.forward_agent = true)/)
106
104
  end
107
105
 
108
- it "can replace underscores in host.name with hypens" do
109
- path = vagrant.instance_variable_get( :@vagrant_path )
110
-
111
- host = make_host( 'name-with_underscore', {} )
112
- vagrant.make_vfile( [host,], options )
106
+ it 'can replace underscores in host.name with hypens' do
107
+ path = vagrant.instance_variable_get(:@vagrant_path)
113
108
 
114
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
115
- expect( vagrantfile ).to match(/v.vm.hostname = .*name-with-underscore/)
109
+ host = make_host('name-with_underscore', {})
110
+ vagrant.make_vfile([host,], options)
116
111
 
112
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
113
+ expect(vagrantfile).to match(/v.vm.hostname = .*name-with-underscore/)
117
114
  end
118
115
 
119
- it "can make a Vagrantfile with synced_folder disabled" do
120
- path = vagrant.instance_variable_get( :@vagrant_path )
116
+ it 'can make a Vagrantfile with synced_folder disabled' do
117
+ path = vagrant.instance_variable_get(:@vagrant_path)
121
118
 
122
- hosts = make_hosts({:synced_folder => 'disabled'},1)
123
- vagrant.make_vfile( hosts, options )
119
+ hosts = make_hosts({ synced_folder: 'disabled' }, 1)
120
+ vagrant.make_vfile(hosts, options)
124
121
 
125
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
126
- expect( vagrantfile ).to match(/v.vm.synced_folder .* disabled: true/)
122
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
123
+ expect(vagrantfile).to match(/v.vm.synced_folder .* disabled: true/)
127
124
  end
128
125
 
129
- it "can make a Vagrantfile with network mac specified" do
130
- path = vagrant.instance_variable_get( :@vagrant_path )
126
+ it 'can make a Vagrantfile with network mac specified' do
127
+ path = vagrant.instance_variable_get(:@vagrant_path)
131
128
 
132
- hosts = make_hosts({:network_mac => 'b6:33:ae:19:48:f9'},1)
133
- vagrant.make_vfile( hosts, options )
129
+ hosts = make_hosts({ network_mac: 'b6:33:ae:19:48:f9' }, 1)
130
+ vagrant.make_vfile(hosts, options)
134
131
 
135
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
136
- expect( vagrantfile ).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "b6:33:ae:19:48:f9/)
132
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
133
+ expect(vagrantfile).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "b6:33:ae:19:48:f9/)
137
134
  end
138
135
 
139
- it "can make a Vagrantfile with improper keys for synced folders" do
140
- path = vagrant.instance_variable_get( :@vagrant_path )
136
+ it 'can make a Vagrantfile with improper keys for synced folders' do
137
+ path = vagrant.instance_variable_get(:@vagrant_path)
141
138
 
142
- hosts = make_hosts({:mount_folders => {
143
- :test_invalid1 => {:host_path => '/invalid1', :container_path => '/invalid1'},
144
- :test_invalid2 => {:from => '/invalid2', :container_path => '/invalid2'},
145
- :test_invalid3 => {:host_path => '/invalid3', :to => '/invalid3'},
146
- :test_valid => {:from => '/valid', :to => '/valid'}
147
- }},1)
148
- vagrant.make_vfile( hosts, options )
139
+ hosts = make_hosts({ mount_folders: {
140
+ test_invalid1: { host_path: '/invalid1', container_path: '/invalid1' },
141
+ test_invalid2: { from: '/invalid2', container_path: '/invalid2' },
142
+ test_invalid3: { host_path: '/invalid3', to: '/invalid3' },
143
+ test_valid: { from: '/valid', to: '/valid' }
144
+ } }, 1)
145
+ vagrant.make_vfile(hosts, options)
149
146
 
150
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
147
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
151
148
 
152
- expect( vagrantfile ).not_to match(/v.vm.synced_folder '', '', create: true/)
153
- expect( vagrantfile ).not_to match(/v.vm.synced_folder '\/invalid2', '', create: true/)
154
- expect( vagrantfile ).not_to match(/v.vm.synced_folder '', '\/invalid3', create: true/)
155
- expect( vagrantfile ).to match(/v.vm.synced_folder '\/valid', '\/valid', create: true/)
149
+ expect(vagrantfile).not_to match(/v.vm.synced_folder '', '', create: true/)
150
+ expect(vagrantfile).not_to match(%r{v.vm.synced_folder '/invalid2', '', create: true})
151
+ expect(vagrantfile).not_to match(%r{v.vm.synced_folder '', '/invalid3', create: true})
152
+ expect(vagrantfile).to match(%r{v.vm.synced_folder '/valid', '/valid', create: true})
156
153
  end
157
154
 
158
- it "can make a Vagrantfile with optional shell provisioner" do
159
- path = vagrant.instance_variable_get( :@vagrant_path )
155
+ it 'can make a Vagrantfile with optional shell provisioner' do
156
+ path = vagrant.instance_variable_get(:@vagrant_path)
160
157
 
161
158
  shell_path = '/path/to/shell/script'
162
159
  hosts = make_hosts({
163
- :shell_provisioner => {
164
- :path => shell_path
165
- }
166
- }, 1)
167
- vagrant.make_vfile( hosts, options )
168
-
169
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
170
- expect( vagrantfile ).to match(/v.vm.provision 'shell', :path => '#{shell_path}'/)
160
+ shell_provisioner: {
161
+ path: shell_path
162
+ }
163
+ }, 1)
164
+ vagrant.make_vfile(hosts, options)
165
+
166
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
167
+ expect(vagrantfile).to match(/v.vm.provision 'shell', :path => '#{shell_path}'/)
171
168
  end
172
169
 
173
- it "can make a Vagrantfile with optional shell provisioner with args" do
174
- path = vagrant.instance_variable_get( :@vagrant_path )
170
+ it 'can make a Vagrantfile with optional shell provisioner with args' do
171
+ path = vagrant.instance_variable_get(:@vagrant_path)
175
172
 
176
173
  shell_path = '/path/to/shell/script.sh'
177
174
  shell_args = 'arg1 arg2'
178
175
  hosts = make_hosts({
179
- :shell_provisioner => {
180
- :path => shell_path,
181
- :args => shell_args
182
- }
183
- }, 1)
184
- vagrant.make_vfile( hosts, options )
185
-
186
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
187
- expect( vagrantfile ).to match(/v.vm.provision 'shell', :path => '#{shell_path}', :args => '#{shell_args}'/)
176
+ shell_provisioner: {
177
+ path: shell_path,
178
+ args: shell_args
179
+ }
180
+ }, 1)
181
+ vagrant.make_vfile(hosts, options)
182
+
183
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
184
+ expect(vagrantfile).to match(/v.vm.provision 'shell', :path => '#{shell_path}', :args => '#{shell_args}'/)
188
185
  end
189
186
 
190
- it "raises an error if path is not set on shell_provisioner" do
191
- path = vagrant.instance_variable_get( :@vagrant_path )
187
+ it 'raises an error if path is not set on shell_provisioner' do
188
+ path = vagrant.instance_variable_get(:@vagrant_path)
192
189
 
193
- hosts = make_hosts({:shell_provisioner => {}}, 1)
194
- expect{ vagrant.make_vfile( hosts, options ) }.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
190
+ hosts = make_hosts({ shell_provisioner: {} }, 1)
191
+ expect do
192
+ vagrant.make_vfile(hosts, options)
193
+ end.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
195
194
  end
196
195
 
197
- it "raises an error if path is EMPTY on shell_provisioner" do
198
- path = vagrant.instance_variable_get( :@vagrant_path )
196
+ it 'raises an error if path is EMPTY on shell_provisioner' do
197
+ path = vagrant.instance_variable_get(:@vagrant_path)
199
198
 
200
199
  empty_shell_path = ''
201
200
  hosts = make_hosts({
202
- :shell_provisioner => {
203
- :path => empty_shell_path
204
- }
205
- }, 1)
206
- expect{ vagrant.make_vfile( hosts, options ) }.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
201
+ shell_provisioner: {
202
+ path: empty_shell_path
203
+ }
204
+ }, 1)
205
+ expect do
206
+ vagrant.make_vfile(hosts, options)
207
+ end.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
207
208
  end
208
209
 
209
- context "when generating a windows config" do
210
+ context 'when generating a windows config' do
210
211
  before do
211
- path = vagrant.instance_variable_get( :@vagrant_path )
212
+ path = vagrant.instance_variable_get(:@vagrant_path)
212
213
  @hosts[0][:platform] = 'windows'
213
214
 
214
- vagrant.make_vfile( @hosts )
215
+ vagrant.make_vfile(@hosts)
215
216
 
216
- @generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
217
+ @generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
217
218
  end
218
219
 
219
220
  it 'has the proper port forwarding for RDP' do
220
- expect( @generated_file ).to match /v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true/
221
+ expect(@generated_file).to match /v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true/
221
222
  end
222
223
 
223
224
  it 'has the proper port forwarding for WinRM' do
224
- expect( @generated_file ).to match /v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true/
225
+ expect(@generated_file).to match /v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true/
225
226
  end
226
227
 
227
228
  it 'configures the guest type to windows' do
228
- expect( @generated_file ).to match /v.vm.guest = :windows/
229
+ expect(@generated_file).to match /v.vm.guest = :windows/
229
230
  end
230
231
 
231
232
  it 'configures the guest type to use winrm' do
232
- expect( @generated_file ).to match /v.vm.communicator = 'winrm'/
233
+ expect(@generated_file).to match /v.vm.communicator = 'winrm'/
233
234
  end
234
235
 
235
236
  it 'sets a non-default memsize' do
236
- expect( @generated_file ).to match /'--memory', '2048',/
237
+ expect(@generated_file).to match /'--memory', '2048',/
237
238
  end
238
239
  end
239
240
 
240
241
  context 'when generating a freebsd config' do
241
242
  before do
242
- path = vagrant.instance_variable_get( :@vagrant_path )
243
+ path = vagrant.instance_variable_get(:@vagrant_path)
243
244
  @hosts[0][:platform] = 'freebsd'
244
245
 
245
- vagrant.make_vfile( @hosts )
246
+ vagrant.make_vfile(@hosts)
246
247
 
247
- @generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
248
+ @generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
248
249
  end
249
250
 
250
251
  it 'has the proper ssh shell' do
251
- expect( @generated_file ).to match /v.ssh.shell = 'sh'\n/
252
+ expect(@generated_file).to match /v.ssh.shell = 'sh'\n/
252
253
  end
253
254
 
254
255
  it 'has the proper guest setting' do
255
- expect( @generated_file ).to match /v.vm.guest = :freebsd\n/
256
+ expect(@generated_file).to match /v.vm.guest = :freebsd\n/
256
257
  end
257
258
  end
258
259
 
259
- it "uses the memsize defined per vagrant host" do
260
- path = vagrant.instance_variable_get( :@vagrant_path )
260
+ it 'uses the memsize defined per vagrant host' do
261
+ path = vagrant.instance_variable_get(:@vagrant_path)
261
262
 
262
- vagrant.make_vfile( @hosts, {'vagrant_memsize' => 'hello!'} )
263
+ vagrant.make_vfile(@hosts, { 'vagrant_memsize' => 'hello!' })
263
264
 
264
- generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
265
+ generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
265
266
 
266
267
  match = generated_file.match(/vb.customize \['modifyvm', :id, '--memory', 'hello!', '--cpus', '1', '--audio', 'none'\]/)
267
268
 
268
- expect( match ).to_not be nil
269
-
269
+ expect(match).to_not be nil
270
270
  end
271
271
 
272
- it "uses the cpus defined per vagrant host" do
273
- path = vagrant.instance_variable_get( :@vagrant_path )
272
+ it 'uses the cpus defined per vagrant host' do
273
+ path = vagrant.instance_variable_get(:@vagrant_path)
274
274
 
275
- vagrant.make_vfile( @hosts, {'vagrant_cpus' => 'goodbye!'} )
275
+ vagrant.make_vfile(@hosts, { 'vagrant_cpus' => 'goodbye!' })
276
276
 
277
- generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
277
+ generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
278
278
 
279
279
  match = generated_file.match(/vb.customize \['modifyvm', :id, '--memory', '1024', '--cpus', 'goodbye!', '--audio', 'none'\]/)
280
280
 
281
- expect( match ).to_not be nil
282
-
281
+ expect(match).to_not be nil
283
282
  end
284
283
 
285
- context "port forwarding rules" do
286
- it "supports all Vagrant parameters" do
287
- path = vagrant.instance_variable_get( :@vagrant_path )
284
+ context 'port forwarding rules' do
285
+ it 'supports all Vagrant parameters' do
286
+ path = vagrant.instance_variable_get(:@vagrant_path)
288
287
 
289
288
  hosts = make_hosts(
290
289
  {
291
- :forwarded_ports => {
292
- :http => {
293
- :from => 10080,
294
- :from_ip => '127.0.0.1',
295
- :to => 80,
296
- :to_ip => '0.0.0.0',
297
- :protocol => 'udp'
290
+ forwarded_ports: {
291
+ http: {
292
+ from: 10_080,
293
+ from_ip: '127.0.0.1',
294
+ to: 80,
295
+ to_ip: '0.0.0.0',
296
+ protocol: 'udp'
298
297
  }
299
298
  }
300
- },1)
301
- vagrant.make_vfile( hosts, options )
299
+ }, 1
300
+ )
301
+ vagrant.make_vfile(hosts, options)
302
302
 
303
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
304
- expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest_ip: '0.0.0.0', guest: 80, host_ip: '127.0.0.1', host: 10080/)
303
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
304
+ expect(vagrantfile).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest_ip: '0.0.0.0', guest: 80, host_ip: '127.0.0.1', host: 10080/)
305
305
  end
306
306
 
307
- it "supports supports from_ip" do
308
- path = vagrant.instance_variable_get( :@vagrant_path )
307
+ it 'supports supports from_ip' do
308
+ path = vagrant.instance_variable_get(:@vagrant_path)
309
309
 
310
310
  hosts = make_hosts(
311
- {
312
- :forwarded_ports => {
313
- :http => {
314
- :from => 10080,
315
- :from_ip => '127.0.0.1',
316
- :to => 80,
317
- }
318
- }
319
- },1)
320
- vagrant.make_vfile( hosts, options )
311
+ {
312
+ forwarded_ports: {
313
+ http: {
314
+ from: 10_080,
315
+ from_ip: '127.0.0.1',
316
+ to: 80,
317
+ }
318
+ }
319
+ }, 1
320
+ )
321
+ vagrant.make_vfile(hosts, options)
321
322
 
322
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
323
- expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest: 80, host_ip: '127.0.0.1', host: 10080/)
323
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
324
+ expect(vagrantfile).to match(/v.vm.network :forwarded_port, guest: 80, host_ip: '127.0.0.1', host: 10080/)
324
325
  end
325
326
 
326
- it "supports all to_ip" do
327
- path = vagrant.instance_variable_get( :@vagrant_path )
327
+ it 'supports all to_ip' do
328
+ path = vagrant.instance_variable_get(:@vagrant_path)
328
329
 
329
330
  hosts = make_hosts(
330
- {
331
- :forwarded_ports => {
332
- :http => {
333
- :from => 10080,
334
- :to => 80,
335
- :to_ip => '0.0.0.0',
336
- }
337
- }
338
- },1)
339
- vagrant.make_vfile( hosts, options )
331
+ {
332
+ forwarded_ports: {
333
+ http: {
334
+ from: 10_080,
335
+ to: 80,
336
+ to_ip: '0.0.0.0',
337
+ }
338
+ }
339
+ }, 1
340
+ )
341
+ vagrant.make_vfile(hosts, options)
340
342
 
341
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
342
- expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest_ip: '0.0.0.0', guest: 80, host: 10080/)
343
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
344
+ expect(vagrantfile).to match(/v.vm.network :forwarded_port, guest_ip: '0.0.0.0', guest: 80, host: 10080/)
343
345
  end
344
346
 
345
- it "supports all protocol" do
346
- path = vagrant.instance_variable_get( :@vagrant_path )
347
+ it 'supports all protocol' do
348
+ path = vagrant.instance_variable_get(:@vagrant_path)
347
349
 
348
350
  hosts = make_hosts(
349
- {
350
- :forwarded_ports => {
351
- :http => {
352
- :from => 10080,
353
- :to => 80,
354
- :protocol => 'udp'
355
- }
356
- }
357
- },1)
358
- vagrant.make_vfile( hosts, options )
359
-
360
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
361
- expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
351
+ {
352
+ forwarded_ports: {
353
+ http: {
354
+ from: 10_080,
355
+ to: 80,
356
+ protocol: 'udp'
357
+ }
358
+ }
359
+ }, 1
360
+ )
361
+ vagrant.make_vfile(hosts, options)
362
362
 
363
+ vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
364
+ expect(vagrantfile).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
363
365
  end
364
366
  end
365
367
 
366
- it "can generate a new /etc/hosts file referencing each host" do
367
-
368
+ it 'can generate a new /etc/hosts file referencing each host' do
368
369
  @hosts.each do |host|
369
- expect( vagrant ).to receive( :get_domain_name ).with( host ).and_return( 'labs.lan' )
370
- expect( vagrant ).to receive( :set_etc_hosts ).with( host, "127.0.0.1\tlocalhost localhost.localdomain\nip.address.for.vm1\tvm1.labs.lan vm1\nip.address.for.vm2\tvm2.labs.lan vm2\nip.address.for.vm3\tvm3.labs.lan vm3\n" ).once
370
+ expect(vagrant).to receive(:get_domain_name).with(host).and_return('labs.lan')
371
+ expect(vagrant).to receive(:set_etc_hosts).with(host,
372
+ "127.0.0.1\tlocalhost localhost.localdomain\nip.address.for.vm1\tvm1.labs.lan vm1\nip.address.for.vm2\tvm2.labs.lan vm2\nip.address.for.vm3\tvm3.labs.lan vm3\n").once
371
373
  end
372
374
 
373
- vagrant.hack_etc_hosts( @hosts, options )
374
-
375
+ vagrant.hack_etc_hosts(@hosts, options)
375
376
  end
376
377
 
377
378
  context "can copy vagrant's key to root .ssh on each host" do
378
-
379
- it "can copy to root on unix" do
379
+ it 'can copy to root on unix' do
380
380
  host = @hosts[0]
381
381
  host[:platform] = 'unix'
382
382
 
383
- expect( Command ).to receive( :new ).with("sudo su -c \"cp -r .ssh /root/.\"").once
384
- expect( Command ).to receive( :new ).with("sudo fixfiles restore /root").once
385
- expect( Command ).to receive( :new ).with("sudo selinuxenabled").once
386
-
387
- vagrant.copy_ssh_to_root( host, options )
383
+ expect(Command).to receive(:new).with('sudo su -c "cp -r .ssh /root/."').once
384
+ expect(Command).to receive(:new).with('sudo fixfiles restore /root').once
385
+ expect(Command).to receive(:new).with('sudo selinuxenabled').once
388
386
 
387
+ vagrant.copy_ssh_to_root(host, options)
389
388
  end
390
389
 
391
- it "can copy to Administrator on windows" do
390
+ it 'can copy to Administrator on windows' do
392
391
  host = @hosts[0]
393
392
  host[:platform] = 'windows'
394
- expect( host ).to receive( :is_cygwin? ).and_return(true)
393
+ expect(host).to receive(:is_cygwin?).and_return(true)
395
394
 
396
- expect( Command ).to_not receive( :new ).with("sudo fixfiles restore /root")
397
- expect( Command ).to receive( :new ).with("cp -r .ssh /cygdrive/c/Users/Administrator/.").once
398
- expect( Command ).to receive( :new ).with("chown -R Administrator /cygdrive/c/Users/Administrator/.ssh").once
395
+ expect(Command).to_not receive(:new).with('sudo fixfiles restore /root')
396
+ expect(Command).to receive(:new).with('cp -r .ssh /cygdrive/c/Users/Administrator/.').once
397
+ expect(Command).to receive(:new).with('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh').once
399
398
 
400
399
  # This is checked on all platforms since Linux isn't called out specifically in the code
401
400
  # If this fails, nothing further is activated
402
401
  result = Beaker::Result.new(host, '')
403
402
  result.exit_code = 1
404
- expect( Command ).to receive( :new ).with("sudo selinuxenabled")
405
- allow( host ).to receive(:exec).and_return(result)
406
-
407
- vagrant.copy_ssh_to_root( host, options )
403
+ expect(Command).to receive(:new).with('sudo selinuxenabled')
404
+ allow(host).to receive(:exec).and_return(result)
408
405
 
406
+ vagrant.copy_ssh_to_root(host, options)
409
407
  end
410
408
  end
411
409
 
412
- describe "set_ssh_config" do
413
- let( :out ) do
410
+ describe 'set_ssh_config' do
411
+ let(:out) do
414
412
  <<-CONFIG
415
413
  Host #{name}
416
414
  HostName 127.0.0.1
@@ -423,9 +421,9 @@ EOF
423
421
  IdentitiesOnly yes
424
422
  CONFIG
425
423
  end
426
- let( :host ) { @hosts[0] }
427
- let( :name ) { host.name }
428
- let( :override_options ) { {} }
424
+ let(:host) { @hosts[0] }
425
+ let(:name) { host.name }
426
+ let(:override_options) { {} }
429
427
 
430
428
  before :each do
431
429
  # FakeFS is just broken with Tempfile
@@ -433,11 +431,11 @@ EOF
433
431
  Dir.mktmpdir do |dir|
434
432
  vagrant.instance_variable_get(:@options).merge!(override_options)
435
433
  vagrant.instance_variable_set(:@vagrant_path, dir)
436
- state = double( 'state' )
437
- allow( state ).to receive( :success? ).and_return( true )
438
- allow( Open3 ).to receive( :capture3 ).with( {"RUBYLIB"=>"", "RUBYOPT"=>""}, 'vagrant', 'ssh-config', name ).and_return( [ out, "", state ])
434
+ state = double('state')
435
+ allow(state).to receive(:success?).and_return(true)
436
+ allow(Open3).to receive(:capture3).with({}, 'vagrant', 'ssh-config', name).and_return([out, '', state])
439
437
 
440
- vagrant.set_ssh_config( host, 'root' )
438
+ vagrant.set_ssh_config(host, 'root')
441
439
  end
442
440
  end
443
441
 
@@ -454,13 +452,13 @@ EOF
454
452
  expect(host['ssh'][:keys_only]).to be === false
455
453
  end
456
454
 
457
- context "when :forward_ssh_agent is false" do
455
+ context 'when :forward_ssh_agent is false' do
458
456
  let(:override_options) do
459
- {forward_ssh_agent: false}
457
+ { forward_ssh_agent: false }
460
458
  end
461
459
 
462
- it "should keep IdentitiesOnly to yes" do
463
- expect( host['ssh'][:keys_only]).to be === true
460
+ it 'should keep IdentitiesOnly to yes' do
461
+ expect(host['ssh'][:keys_only]).to be === true
464
462
  end
465
463
  end
466
464
  end
@@ -517,87 +515,80 @@ EOF
517
515
  end
518
516
  end
519
517
 
520
- describe "provisioning and cleanup" do
521
-
518
+ describe 'provisioning and cleanup' do
522
519
  before :each do
523
- expect( vagrant ).to receive( :vagrant_cmd ).with( "up" ).once
520
+ expect(vagrant).to receive(:vagrant_cmd).with('up').once
524
521
  @hosts.each do |host|
525
522
  host_prev_name = host['user']
526
- expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once
527
- expect( vagrant ).to receive( :copy_ssh_to_root ).with( host, options ).once
528
- expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
523
+ expect(vagrant).to receive(:set_ssh_config).with(host, 'vagrant').once
524
+ expect(vagrant).to receive(:copy_ssh_to_root).with(host, options).once
525
+ expect(vagrant).to receive(:set_ssh_config).with(host, host_prev_name).once
529
526
  end
530
- expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
527
+ expect(vagrant).to receive(:hack_etc_hosts).with(@hosts, options).once
531
528
  end
532
529
 
533
- it "can provision a set of hosts" do
534
- options = vagrant.instance_variable_get( :@options )
535
- expect( vagrant ).to receive( :make_vfile ).with( @hosts, options ).once
536
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).never
530
+ it 'can provision a set of hosts' do
531
+ options = vagrant.instance_variable_get(:@options)
532
+ expect(vagrant).to receive(:make_vfile).with(@hosts, options).once
533
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').never
537
534
  vagrant.provision
538
535
  end
539
536
 
540
- it "destroys an existing set of hosts before provisioning" do
541
- vagrant.make_vfile( @hosts )
542
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
537
+ it 'destroys an existing set of hosts before provisioning' do
538
+ vagrant.make_vfile(@hosts)
539
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
543
540
  vagrant.provision
544
541
  end
545
542
 
546
- it "notifies user of failed provision" do
543
+ it 'notifies user of failed provision' do
547
544
  vagrant.provision
548
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).and_raise( RuntimeError )
549
- expect( options['logger'] ).to receive( :debug ).with( /Vagrantfile/ )
550
- expect{ vagrant.provision }.to raise_error( RuntimeError )
545
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').and_raise(RuntimeError)
546
+ expect(options['logger']).to receive(:debug).with(/Vagrantfile/)
547
+ expect { vagrant.provision }.to raise_error(RuntimeError)
551
548
  end
552
549
 
553
- it "can cleanup" do
554
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
555
- expect( FileUtils ).to receive( :rm_rf ).once
550
+ it 'can cleanup' do
551
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
552
+ expect(FileUtils).to receive(:rm_rf).once
556
553
 
557
554
  vagrant.provision
558
555
  vagrant.cleanup
559
-
560
556
  end
561
-
562
557
  end
563
558
 
564
- describe "provisioning and cleanup on windows" do
559
+ describe 'provisioning and cleanup on windows' do
565
560
  before :each do
566
- expect( vagrant ).to receive( :vagrant_cmd ).with( "up" ).once
561
+ expect(vagrant).to receive(:vagrant_cmd).with('up').once
567
562
  @hosts.each do |host|
568
563
  host[:platform] = 'windows'
569
564
  host_prev_name = host['user']
570
- expect( vagrant ).not_to receive( :set_ssh_config ).with( host, 'vagrant' )
571
- expect( vagrant ).not_to receive( :copy_ssh_to_root ).with( host, options )
572
- expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
565
+ expect(vagrant).not_to receive(:set_ssh_config).with(host, 'vagrant')
566
+ expect(vagrant).not_to receive(:copy_ssh_to_root).with(host, options)
567
+ expect(vagrant).to receive(:set_ssh_config).with(host, host_prev_name).once
573
568
  end
574
- expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
569
+ expect(vagrant).to receive(:hack_etc_hosts).with(@hosts, options).once
575
570
  end
576
571
 
577
- it "can provision a set of hosts" do
578
- options = vagrant.instance_variable_get( :@options )
579
- expect( vagrant ).to receive( :make_vfile ).with( @hosts, options ).once
580
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).never
572
+ it 'can provision a set of hosts' do
573
+ options = vagrant.instance_variable_get(:@options)
574
+ expect(vagrant).to receive(:make_vfile).with(@hosts, options).once
575
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').never
581
576
  vagrant.provision
582
577
  end
583
578
 
584
- it "destroys an existing set of hosts before provisioning" do
585
- vagrant.make_vfile( @hosts )
586
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
579
+ it 'destroys an existing set of hosts before provisioning' do
580
+ vagrant.make_vfile(@hosts)
581
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
587
582
  vagrant.provision
588
583
  end
589
584
 
590
- it "can cleanup" do
591
- expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
592
- expect( FileUtils ).to receive( :rm_rf ).once
585
+ it 'can cleanup' do
586
+ expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
587
+ expect(FileUtils).to receive(:rm_rf).once
593
588
 
594
589
  vagrant.provision
595
590
  vagrant.cleanup
596
-
597
591
  end
598
-
599
592
  end
600
-
601
593
  end
602
-
603
594
  end