beaker 2.44.0 → 2.45.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.
Files changed (37) hide show
  1. checksums.yaml +8 -8
  2. data/CONTRIBUTING.md +7 -2
  3. data/HISTORY.md +200 -2
  4. data/acceptance/tests/puppet/web_helpers_test.rb +55 -0
  5. data/docs/Beaker-Libraries.md +2 -0
  6. data/docs/How-To-Beaker.md +0 -1
  7. data/docs/README.md +1 -1
  8. data/docs/how_to/change_terminal_output_coloring.md +32 -0
  9. data/docs/hypervisors/README.md +1 -1
  10. data/docs/hypervisors/openstack.md +80 -4
  11. data/docs/hypervisors/vagrant.md +40 -2
  12. data/docs/runner/test_run.md +31 -0
  13. data/lib/beaker/cli.rb +3 -3
  14. data/lib/beaker/dsl/helpers/web_helpers.rb +13 -4
  15. data/lib/beaker/dsl/install_utils/foss_utils.rb +1 -1
  16. data/lib/beaker/dsl/install_utils/windows_utils.rb +3 -3
  17. data/lib/beaker/host.rb +21 -1
  18. data/lib/beaker/host/unix/pkg.rb +1 -1
  19. data/lib/beaker/hypervisor/openstack.rb +1 -1
  20. data/lib/beaker/hypervisor/vagrant.rb +15 -1
  21. data/lib/beaker/options/hosts_file_parser.rb +54 -14
  22. data/lib/beaker/options/parser.rb +37 -3
  23. data/lib/beaker/options/presets.rb +2 -2
  24. data/lib/beaker/version.rb +1 -1
  25. data/spec/beaker/cli_spec.rb +4 -1
  26. data/spec/beaker/dsl/install_utils/foss_utils_spec.rb +37 -60
  27. data/spec/beaker/dsl/install_utils/windows_utils_spec.rb +3 -3
  28. data/spec/beaker/host/unix/pkg_spec.rb +20 -0
  29. data/spec/beaker/host_prebuilt_steps_spec.rb +7 -7
  30. data/spec/beaker/host_spec.rb +44 -0
  31. data/spec/beaker/hypervisor/openstack_spec.rb +66 -0
  32. data/spec/beaker/hypervisor/vagrant_spec.rb +99 -0
  33. data/spec/beaker/options/hosts_file_parser_spec.rb +95 -22
  34. data/spec/beaker/options/parser_spec.rb +93 -1
  35. data/spec/helpers.rb +10 -2
  36. metadata +6 -3
  37. data/docs/Overview.md +0 -31
@@ -42,11 +42,11 @@ describe ClassMixedWithDSLInstallUtils do
42
42
 
43
43
  def expect_version_log_called(times = hosts.length)
44
44
  [
45
- "\"%ProgramFiles%\\Puppet Labs\\puppet\\misc\\versions.txt\"",
46
- "\"%ProgramFiles(x86)%\\Puppet Labs\\puppet\\misc\\versions.txt\"",
45
+ "\\\"%ProgramFiles%\\Puppet Labs\\puppet\\misc\\versions.txt\\\"",
46
+ "\\\"%ProgramFiles(x86)%\\Puppet Labs\\puppet\\misc\\versions.txt\\\"",
47
47
  ].each do |path|
48
48
  expect( Beaker::Command ).to receive( :new )
49
- .with( "if exist #{path} type #{path}", [], {:cmdexe => true} )
49
+ .with( "\"if exist #{path} type #{path}\"", [], {:cmdexe => true} )
50
50
  .exactly( times ).times
51
51
  end
52
52
  end
@@ -243,6 +243,26 @@ module Beaker
243
243
  expect( instance ).to receive(:exec).with('', {}).and_return(generate_result("hello", {:exit_code => 0}))
244
244
  expect(instance.uninstall_package('pkg')).to be == "hello"
245
245
  end
246
+
247
+ (1..21).to_a.each do | fedora_release |
248
+ it "uses yum on fedora-#{fedora_release}" do
249
+ @opts = {'platform' => "fedora-#{fedora_release}-is-me"}
250
+ pkg = 'fedora_package'
251
+ expect( Beaker::Command ).to receive(:new).with("yum -y remove #{pkg}", [], {:prepend_cmds=>nil, :cmdexe=>false}).and_return('')
252
+ expect( instance ).to receive(:exec).with('', {}).and_return(generate_result("hello", {:exit_code => 0}))
253
+ expect( instance.uninstall_package(pkg) ).to be == "hello"
254
+ end
255
+ end
256
+
257
+ (22..29).to_a.each do | fedora_release |
258
+ it "uses dnf on fedora-#{fedora_release}" do
259
+ @opts = {'platform' => "fedora-#{fedora_release}-is-me"}
260
+ pkg = 'fedora_package'
261
+ expect( Beaker::Command ).to receive(:new).with("dnf -y remove #{pkg}", [], {:prepend_cmds=>nil, :cmdexe=>false}).and_return('')
262
+ expect( instance ).to receive(:exec).with('', {}).and_return(generate_result("hello", {:exit_code => 0}))
263
+ expect( instance.uninstall_package(pkg) ).to be == "hello"
264
+ end
265
+ end
246
266
  end
247
267
  end
248
268
 
@@ -169,19 +169,19 @@ describe Beaker do
169
169
  it "can return the correct url for an el-7 host" do
170
170
  host = make_host( 'testhost', { :platform => Beaker::Platform.new('el-7-platform') } )
171
171
 
172
- expect( subject.epel_info_for( host, options )).to be === ["http://mirrors.kernel.org/fedora-epel/7", "x86_64", "epel-release-7-6.noarch.rpm"]
172
+ expect( subject.epel_info_for( host, options )).to be === ["http://dl.fedoraproject.org/pub/epel/7", "x86_64", "epel-release-7-7.noarch.rpm"]
173
173
  end
174
174
 
175
175
  it "can return the correct url for an el-6 host" do
176
176
  host = make_host( 'testhost', { :platform => Beaker::Platform.new('el-6-platform') } )
177
177
 
178
- expect( subject.epel_info_for( host, options )).to be === ["http://mirrors.kernel.org/fedora-epel/6", "i386", "epel-release-6-8.noarch.rpm"]
178
+ expect( subject.epel_info_for( host, options )).to be === ["http://dl.fedoraproject.org/pub/epel/6", "i386", "epel-release-6-8.noarch.rpm"]
179
179
  end
180
180
 
181
181
  it "can return the correct url for an el-5 host" do
182
182
  host = make_host( 'testhost', { :platform => Beaker::Platform.new('el-5-platform') } )
183
183
 
184
- expect( subject.epel_info_for( host, options )).to be === ["http://mirrors.kernel.org/fedora-epel/5", "i386", "epel-release-5-4.noarch.rpm"]
184
+ expect( subject.epel_info_for( host, options )).to be === ["http://dl.fedoraproject.org/pub/epel/5", "i386", "epel-release-5-4.noarch.rpm"]
185
185
 
186
186
  end
187
187
 
@@ -335,10 +335,10 @@ describe Beaker do
335
335
  hosts[4][:platform] = Beaker::Platform.new('oracle-5-arch')
336
336
 
337
337
  expect( Beaker::Command ).to receive( :new ).with("rpm -qa | grep epel-release").exactly( 6 ).times
338
- expect( Beaker::Command ).to receive( :new ).with("rpm -i http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm").exactly( 4 ).times
339
- expect( Beaker::Command ).to receive( :new ).with("rpm -i http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm").exactly( 2 ).times
340
- expect( Beaker::Command ).to receive( :new ).with("sed -i -e 's;#baseurl.*$;baseurl=http://mirrors\\.kernel\\.org/fedora\\-epel/6/$basearch;' /etc/yum.repos.d/epel.repo").exactly( 4 ).times
341
- expect( Beaker::Command ).to receive( :new ).with("sed -i -e 's;#baseurl.*$;baseurl=http://mirrors\\.kernel\\.org/fedora\\-epel/5/$basearch;' /etc/yum.repos.d/epel.repo").exactly( 2 ).times
338
+ expect( Beaker::Command ).to receive( :new ).with("rpm -i http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm").exactly( 4 ).times
339
+ expect( Beaker::Command ).to receive( :new ).with("rpm -i http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm").exactly( 2 ).times
340
+ expect( Beaker::Command ).to receive( :new ).with("sed -i -e 's;#baseurl.*$;baseurl=http://dl\\.fedoraproject\\.org/pub/epel/6/$basearch;' /etc/yum.repos.d/epel.repo").exactly( 4 ).times
341
+ expect( Beaker::Command ).to receive( :new ).with("sed -i -e 's;#baseurl.*$;baseurl=http://dl\\.fedoraproject\\.org/pub/epel/5/$basearch;' /etc/yum.repos.d/epel.repo").exactly( 2 ).times
342
342
  expect( Beaker::Command ).to receive( :new ).with("sed -i -e '/mirrorlist/d' /etc/yum.repos.d/epel.repo").exactly( 6 ).times
343
343
  expect( Beaker::Command ).to receive( :new ).with("yum clean all && yum makecache").exactly( 6 ).times
344
344
 
@@ -696,5 +696,49 @@ module Beaker
696
696
  end
697
697
  end
698
698
 
699
+ describe '#get_public_ip' do
700
+ let (:aws) { double('AWSmock')}
701
+ it 'calls upon the ec2 instance to get the ip address' do
702
+ host.host_hash[:hypervisor] = 'ec2'
703
+ host.host_hash[:instance] = aws
704
+ expect(aws).to receive(:ip_address)
705
+ host.get_public_ip
706
+ end
707
+
708
+ it 'returns nil when no matching hypervisor is found' do
709
+ host.host_hash[:hypervisor] = 'vmpooler'
710
+ expect(host.get_public_ip).to be(nil)
711
+ end
712
+
713
+ it 'calls execute with curl if the host_hash[:instance] is not defined and the host is not an instance of Windows::Host' do
714
+ host.host_hash[:hypervisor] = 'ec2'
715
+ host.host_hash[:instance] = nil
716
+ expect(host).to receive(:instance_of?).with(Windows::Host).and_return(false)
717
+ expect(host).to receive(:execute).with("curl http://169.254.169.254/latest/meta-data/public-ipv4").and_return('127.0.0.1')
718
+ host.get_public_ip
719
+ end
720
+
721
+ it 'calls execute with wget if the host_hash[:instance] is not defined and the host is an instance of Windows::Host' do
722
+ host.host_hash[:hypervisor] = 'ec2'
723
+ host.host_hash[:instance] = nil
724
+ expect(host).to receive(:instance_of?).with(Windows::Host).and_return(true)
725
+ expect(host).to receive(:execute).with("wget http://169.254.169.254/latest/meta-data/public-ipv4").and_return('127.0.0.1')
726
+ host.get_public_ip
727
+ end
728
+ end
729
+
730
+ describe '#ip' do
731
+ it 'calls #get_ip when get_public_ip returns nil' do
732
+ allow( host ).to receive(:get_public_ip).and_return(nil)
733
+ expect(host).to receive(:get_ip).and_return('127.0.0.2')
734
+ expect(host.ip).to eq('127.0.0.2')
735
+ end
736
+
737
+ it 'does not call get_ip when #get_public_ip returns an address' do
738
+ allow( host ).to receive(:get_public_ip).and_return('127.0.0.1')
739
+ expect(host).to_not receive(:get_ip)
740
+ expect(host.ip).to eq('127.0.0.1')
741
+ end
742
+ end
699
743
  end
700
744
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'fog'
3
+
4
+ module Beaker
5
+ describe OpenStack do
6
+
7
+ let(:options) { make_opts.merge({'logger' => double().as_null_object}) }
8
+
9
+ let(:openstack) {
10
+ OpenStack.new(@hosts, options)
11
+ }
12
+
13
+ before :each do
14
+ @hosts = make_hosts()
15
+
16
+ @compute_client = double().as_null_object
17
+ @network_client = double().as_null_object
18
+
19
+ allow( Fog::Compute ).to receive( :new ).and_return( @compute_client )
20
+ allow( Fog::Network ).to receive( :new ).and_return( @network_client )
21
+ end
22
+
23
+ it 'check openstack options during initialization' do
24
+ options = openstack.instance_eval('@options')
25
+ expect(options['openstack_api_key']).to eq('P1as$w0rd')
26
+ expect(options['openstack_username']).to eq('user')
27
+ expect(options['openstack_auth_url']).to eq('http://openstack_hypervisor.labs.net:5000/v2.0/tokens')
28
+ expect(options['openstack_tenant']).to eq('testing')
29
+ expect(options['openstack_network']).to eq('testing')
30
+ expect(options['openstack_keyname']).to eq('nopass')
31
+ end
32
+
33
+ it 'check hosts options during initialization' do
34
+ hosts = openstack.instance_eval('@hosts')
35
+ @hosts.each do |host|
36
+ expect(host['image']).to eq('default_image')
37
+ expect(host['flavor']).to eq('m1.large')
38
+ expect(host['user_data']).to eq('#cloud-config\nmanage_etc_hosts: true\nfinal_message: "The host is finally up!"')
39
+ end
40
+ end
41
+
42
+ it 'check host options during server creation' do
43
+
44
+ mock_flavor = Object.new
45
+ allow( mock_flavor ).to receive( :id ).and_return( 12345 )
46
+ allow( openstack ).to receive( :flavor ).and_return( mock_flavor )
47
+ expect( openstack ).to receive( :flavor ).with( 'm1.large' )
48
+
49
+ mock_image = Object.new
50
+ allow( mock_image ).to receive( :id ).and_return( 54321 )
51
+ allow( openstack ).to receive( :image ).and_return( mock_image )
52
+ expect( openstack ).to receive( :image ).with( 'default_image' )
53
+
54
+ mock_servers = double().as_null_object
55
+ allow( @compute_client ).to receive( :servers ).and_return( mock_servers )
56
+ expect(mock_servers).to receive(:create).with(hash_including(
57
+ :user_data => '#cloud-config\nmanage_etc_hosts: true\nfinal_message: "The host is finally up!"',
58
+ :flavor_ref => 12345,
59
+ :image_ref => 54321)
60
+ )
61
+
62
+ openstack.provision
63
+ end
64
+
65
+ end
66
+ end
@@ -18,6 +18,11 @@ module Beaker
18
18
  :mount_folders => {
19
19
  :test_temp => {:from => './', :to => '/temp'},
20
20
  :test_tmp => {:from => '../', :to => '/tmp'}
21
+ },
22
+ :forwarded_ports => {
23
+ :http => {:from => 10080, :to => 80},
24
+ :ssl => {:from => 4443, :to => 443},
25
+ :tomcat => {:from => 8080, :to => 8080}
21
26
  }
22
27
  })
23
28
  end
@@ -49,6 +54,9 @@ Vagrant.configure("2") do |c|
49
54
  v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "0123456789"
50
55
  v.vm.synced_folder './', '/temp', create: true
51
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
52
60
  v.vm.provider :virtualbox do |vb|
53
61
  vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
54
62
  end
@@ -61,6 +69,9 @@ Vagrant.configure("2") do |c|
61
69
  v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0", :mac => "0123456789"
62
70
  v.vm.synced_folder './', '/temp', create: true
63
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
64
75
  v.vm.provider :virtualbox do |vb|
65
76
  vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
66
77
  end
@@ -73,6 +84,9 @@ Vagrant.configure("2") do |c|
73
84
  v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0", :mac => "0123456789"
74
85
  v.vm.synced_folder './', '/temp', create: true
75
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
76
90
  v.vm.provider :virtualbox do |vb|
77
91
  vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
78
92
  end
@@ -152,6 +166,91 @@ EOF
152
166
 
153
167
  end
154
168
 
169
+ context "port forwarding rules" do
170
+ it "supports all Vagrant parameters" do
171
+ path = vagrant.instance_variable_get( :@vagrant_path )
172
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
173
+
174
+ hosts = make_hosts(
175
+ {
176
+ :forwarded_ports => {
177
+ :http => {
178
+ :from => 10080,
179
+ :from_ip => '127.0.0.1',
180
+ :to => 80,
181
+ :to_ip => '0.0.0.0',
182
+ :protocol => 'udp'
183
+ }
184
+ }
185
+ },1)
186
+ vagrant.make_vfile( hosts, options )
187
+
188
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
189
+ 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/)
190
+ end
191
+
192
+ it "supports supports from_ip" do
193
+ path = vagrant.instance_variable_get( :@vagrant_path )
194
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
195
+
196
+ hosts = make_hosts(
197
+ {
198
+ :forwarded_ports => {
199
+ :http => {
200
+ :from => 10080,
201
+ :from_ip => '127.0.0.1',
202
+ :to => 80,
203
+ }
204
+ }
205
+ },1)
206
+ vagrant.make_vfile( hosts, options )
207
+
208
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
209
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest: 80, host_ip: '127.0.0.1', host: 10080/)
210
+ end
211
+
212
+ it "supports all to_ip" do
213
+ path = vagrant.instance_variable_get( :@vagrant_path )
214
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
215
+
216
+ hosts = make_hosts(
217
+ {
218
+ :forwarded_ports => {
219
+ :http => {
220
+ :from => 10080,
221
+ :to => 80,
222
+ :to_ip => '0.0.0.0',
223
+ }
224
+ }
225
+ },1)
226
+ vagrant.make_vfile( hosts, options )
227
+
228
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
229
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest_ip: '0.0.0.0', guest: 80, host: 10080/)
230
+ end
231
+
232
+ it "supports all protocol" do
233
+ path = vagrant.instance_variable_get( :@vagrant_path )
234
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
235
+
236
+ hosts = make_hosts(
237
+ {
238
+ :forwarded_ports => {
239
+ :http => {
240
+ :from => 10080,
241
+ :to => 80,
242
+ :protocol => 'udp'
243
+ }
244
+ }
245
+ },1)
246
+ vagrant.make_vfile( hosts, options )
247
+
248
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
249
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
250
+
251
+ end
252
+ end
253
+
155
254
  it "can generate a new /etc/hosts file referencing each host" do
156
255
 
157
256
  @hosts.each do |host|
@@ -7,36 +7,109 @@ module Beaker
7
7
  let(:parser) {HostsFileParser}
8
8
  let(:filepath) {File.join(File.expand_path(File.dirname(__FILE__)), "data", "hosts.cfg")}
9
9
 
10
- it "can correctly read a host file" do
11
- FakeFS.deactivate!
12
- config = parser.parse_hosts_file(filepath)
13
- expect(config).to be === {:HOSTS=>{:"pe-ubuntu-lucid"=>{:roles=>["agent", "dashboard", "database", "master"], :vmname=>"pe-ubuntu-lucid", :platform=>"ubuntu-10.04-i386", :snapshot=>"clean-w-keys", :hypervisor=>"fusion"}, :"pe-centos6"=>{:roles=>["agent"], :vmname=>"pe-centos6", :platform=>"el-6-i386", :hypervisor=>"fusion", :snapshot=>"clean-w-keys"}}, :nfs_server=>"none", :consoleport=>443}
14
- end
10
+ describe '#parse_hosts_file' do
11
+ it "can correctly read a host file" do
12
+ FakeFS.deactivate!
13
+ config = parser.parse_hosts_file(filepath)
14
+ expect(config).to be === {:HOSTS=>{:"pe-ubuntu-lucid"=>{:roles=>["agent", "dashboard", "database", "master"], :vmname=>"pe-ubuntu-lucid", :platform=>"ubuntu-10.04-i386", :snapshot=>"clean-w-keys", :hypervisor=>"fusion"}, :"pe-centos6"=>{:roles=>["agent"], :vmname=>"pe-centos6", :platform=>"el-6-i386", :hypervisor=>"fusion", :snapshot=>"clean-w-keys"}}, :nfs_server=>"none", :consoleport=>443}
15
+ end
15
16
 
16
- it "can merge CONFIG section into overall hash" do
17
- FakeFS.deactivate!
18
- config = parser.parse_hosts_file(filepath)
19
- expect(config['CONFIG']).to be === nil
20
- expect(config['consoleport']).to be === 443
21
- end
17
+ it "can merge CONFIG section into overall hash" do
18
+ FakeFS.deactivate!
19
+ config = parser.parse_hosts_file(filepath)
20
+ expect(config['CONFIG']).to be === nil
21
+ expect(config['consoleport']).to be === 443
22
+ end
23
+
24
+ it "returns empty configuration when no file provided" do
25
+ FakeFS.deactivate!
26
+ expect(parser.parse_hosts_file()).to be === { :HOSTS => {} }
27
+ end
28
+
29
+ it "raises an error on no file found" do
30
+ FakeFS.deactivate!
31
+ expect{parser.parse_hosts_file("not a valid path")}.to raise_error(Errno::ENOENT)
32
+ end
22
33
 
23
- it "returns empty configuration when no file provided" do
24
- FakeFS.deactivate!
25
- expect(parser.parse_hosts_file()).to be === { :HOSTS => {} }
34
+ it "raises an error on bad yaml file" do
35
+ FakeFS.deactivate!
36
+ allow( YAML ).to receive(:load_file) { raise Psych::SyntaxError }
37
+ allow( File ).to receive(:exists?).and_return(true)
38
+ expect { parser.parse_hosts_file("not a valid path") }.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it 'returns a #new_host_options hash if given no arguments' do
42
+ host_options = parser.parse_hosts_file
43
+ expect( host_options ).to be === parser.new_host_options
44
+ end
45
+
46
+ it 'passes a YAML.load_file call through to #merge_hosts_yaml' do
47
+ yaml_string = 'not actually yaml, but that wont matter'
48
+ allow( File ).to receive( :expand_path ).with( yaml_string ) { yaml_string }
49
+ expect( YAML ).to receive( :load_file ).with( yaml_string )
50
+ parser.parse_hosts_file( yaml_string )
51
+ end
26
52
  end
27
53
 
28
- it "raises an error on no file found" do
29
- FakeFS.deactivate!
30
- expect{parser.parse_hosts_file("not a valid path")}.to raise_error(ArgumentError)
54
+ describe '#parse_hosts_string' do
55
+
56
+ it 'will return a #new_host_options hash if given no arguments' do
57
+ host_options = parser.parse_hosts_string
58
+ expect( host_options ).to be === parser.new_host_options
59
+ end
60
+
61
+ it 'passes a YAML.load call through to #merge_hosts_yaml' do
62
+ yaml_string = 'not actually yaml, but that wont matter'
63
+ expect( YAML ).to receive( :load ).with( yaml_string )
64
+ parser.parse_hosts_string( yaml_string )
65
+ end
31
66
  end
32
67
 
33
- it "raises an error on bad yaml file" do
34
- FakeFS.deactivate!
35
- allow( YAML ).to receive(:load_file) { raise Psych::SyntaxError }
36
- allow( File ).to receive(:exists?).and_return(true)
37
- expect { parser.parse_hosts_file("not a valid path") }.to raise_error(ArgumentError)
68
+ describe '#merge_hosts_yaml' do
69
+ it 'merges yielded block result with host_options argument & returns it' do
70
+ host_options = {}
71
+ yield_to_merge = { :pants => 'truth to the face' }
72
+ block_count = 0
73
+ answer = parser.merge_hosts_yaml( host_options, 'err_msg' ) {
74
+ block_count += 1
75
+ yield_to_merge
76
+ }
77
+
78
+ expect( block_count ).to be === 1
79
+ expect( answer ).to be === host_options.merge( yield_to_merge )
80
+ end
81
+
82
+ class MockSyntaxError < Psych::SyntaxError
83
+ def initialize
84
+ super( '', 0, 0, 0, '', '' )
85
+ end
86
+ end
87
+
88
+ it 'raises an ArgumentError if can\'t process YAML' do
89
+ # allow( parser ).to receive( :merge_hosts_yaml )
90
+ err_value = 'err_msg8797'
91
+ expect {
92
+ parser.merge_hosts_yaml( {}, err_value ) {
93
+ raise MockSyntaxError
94
+ }
95
+ }.to raise_error( ArgumentError, /#{err_value}/ )
96
+ end
38
97
  end
39
98
 
99
+ describe '#fix_roles_array' do
100
+ it 'adds a roles array to a host if not present' do
101
+ host_options = { 'HOSTS' => {
102
+ 'host1' => {},
103
+ 'host2' => {}
104
+ }}
105
+
106
+ parser.fix_roles_array( host_options )
107
+
108
+ host_options['HOSTS'].each do |host_name, host_hash|
109
+ expect( host_hash['roles'] ).to be === []
110
+ end
111
+ end
112
+ end
40
113
  end
41
114
  end
42
115
  end