beaker 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +8 -0
- data/README.md +6 -6
- data/beaker.gemspec +6 -2
- data/lib/beaker.rb +1 -1
- data/lib/beaker/answers.rb +34 -7
- data/lib/beaker/answers/version20.rb +124 -0
- data/lib/beaker/answers/version28.rb +21 -0
- data/lib/beaker/answers/version30.rb +24 -5
- data/lib/beaker/cli.rb +55 -41
- data/lib/beaker/command.rb +2 -2
- data/lib/beaker/dsl/helpers.rb +320 -106
- data/lib/beaker/dsl/install_utils.rb +202 -81
- data/lib/beaker/dsl/roles.rb +40 -0
- data/lib/beaker/host.rb +28 -20
- data/lib/beaker/host/unix.rb +7 -4
- data/lib/beaker/host/unix/pkg.rb +42 -12
- data/lib/beaker/host/windows.rb +9 -5
- data/lib/beaker/host/windows/group.rb +1 -1
- data/lib/beaker/host/windows/pkg.rb +41 -8
- data/lib/beaker/hypervisor.rb +23 -10
- data/lib/beaker/hypervisor/aixer.rb +15 -19
- data/lib/beaker/hypervisor/blimper.rb +71 -72
- data/lib/beaker/hypervisor/fusion.rb +11 -10
- data/lib/beaker/hypervisor/solaris.rb +17 -23
- data/lib/beaker/hypervisor/vagrant.rb +27 -12
- data/lib/beaker/hypervisor/vcloud.rb +154 -138
- data/lib/beaker/hypervisor/vcloud_pooled.rb +97 -0
- data/lib/beaker/hypervisor/vsphere.rb +8 -5
- data/lib/beaker/hypervisor/vsphere_helper.rb +43 -33
- data/lib/beaker/network_manager.rb +16 -12
- data/lib/beaker/options/command_line_parser.rb +199 -0
- data/lib/beaker/options/hosts_file_parser.rb +39 -0
- data/lib/beaker/options/options_file_parser.rb +45 -0
- data/lib/beaker/options/options_hash.rb +294 -0
- data/lib/beaker/options/parser.rb +288 -0
- data/lib/beaker/options/pe_version_scraper.rb +35 -0
- data/lib/beaker/options/presets.rb +70 -0
- data/lib/beaker/shared.rb +2 -1
- data/lib/beaker/shared/host_handler.rb +7 -2
- data/lib/beaker/shared/repetition.rb +1 -0
- data/lib/beaker/shared/timed.rb +14 -0
- data/lib/beaker/test_case.rb +2 -38
- data/lib/beaker/test_suite.rb +11 -25
- data/lib/beaker/utils/repo_control.rb +6 -8
- data/lib/beaker/utils/setup_helper.rb +9 -20
- data/spec/beaker/answers_spec.rb +109 -0
- data/spec/beaker/command_spec.rb +2 -2
- data/spec/beaker/dsl/assertions_spec.rb +1 -3
- data/spec/beaker/dsl/helpers_spec.rb +519 -84
- data/spec/beaker/dsl/install_utils_spec.rb +265 -16
- data/spec/beaker/dsl/roles_spec.rb +31 -10
- data/spec/beaker/host/windows/group_spec.rb +55 -0
- data/spec/beaker/host_spec.rb +130 -40
- data/spec/beaker/hypervisor/aixer_spec.rb +34 -0
- data/spec/beaker/hypervisor/blimper_spec.rb +77 -0
- data/spec/beaker/hypervisor/fusion_spec.rb +26 -0
- data/spec/beaker/hypervisor/hypervisor_spec.rb +66 -0
- data/spec/beaker/hypervisor/solaris_spec.rb +39 -0
- data/spec/beaker/hypervisor/vagrant_spec.rb +105 -0
- data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +60 -0
- data/spec/beaker/hypervisor/vcloud_spec.rb +70 -0
- data/spec/beaker/hypervisor/vsphere_helper_spec.rb +162 -0
- data/spec/beaker/hypervisor/vsphere_spec.rb +76 -0
- data/spec/beaker/options/command_line_parser_spec.rb +25 -0
- data/spec/beaker/options/data/LATEST +1 -0
- data/spec/beaker/options/data/badyaml.cfg +21 -0
- data/spec/beaker/options/data/hosts.cfg +21 -0
- data/spec/beaker/options/data/opts.txt +6 -0
- data/spec/beaker/options/hosts_file_parser_spec.rb +30 -0
- data/spec/beaker/options/options_file_parser_spec.rb +23 -0
- data/spec/beaker/options/options_hash_spec.rb +111 -0
- data/spec/beaker/options/parser_spec.rb +172 -0
- data/spec/beaker/options/pe_version_scaper_spec.rb +15 -0
- data/spec/beaker/options/presets_spec.rb +24 -0
- data/spec/beaker/puppet_command_spec.rb +54 -21
- data/spec/beaker/shared/error_handler_spec.rb +40 -0
- data/spec/beaker/shared/host_handler_spec.rb +104 -0
- data/spec/beaker/shared/repetition_spec.rb +72 -0
- data/spec/beaker/test_suite_spec.rb +3 -16
- data/spec/beaker/utils/ntp_control_spec.rb +42 -0
- data/spec/beaker/utils/repo_control_spec.rb +168 -0
- data/spec/beaker/utils/setup_helper_spec.rb +82 -0
- data/spec/beaker/utils/validator_spec.rb +58 -0
- data/spec/helpers.rb +97 -0
- data/spec/matchers.rb +39 -0
- data/spec/mock_blimpy.rb +48 -0
- data/spec/mock_fission.rb +60 -0
- data/spec/mock_vsphere.rb +310 -0
- data/spec/mock_vsphere_helper.rb +183 -0
- data/spec/mocks.rb +83 -0
- data/spec/spec_helper.rb +8 -1
- metadata +106 -13
- data/beaker.rb +0 -10
- data/lib/beaker/options_parsing.rb +0 -323
- data/lib/beaker/test_config.rb +0 -148
- data/spec/beaker/options_parsing_spec.rb +0 -37
- data/spec/mocks_and_helpers.rb +0 -34
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
describe VsphereHelper do
|
5
|
+
let( :logger ) { double('logger').as_null_object }
|
6
|
+
let( :vInfo ) { { :server => "vsphere.labs.net", :user => "vsphere@labs.com", :pass => "supersekritpassword" } }
|
7
|
+
let( :vsphere_helper ) { VsphereHelper.new ( vInfo.merge( { :logger => logger } ) ) }
|
8
|
+
let( :snaplist ) { { 'snap1' => { 'snap1sub1' => nil ,
|
9
|
+
'snap1sub2' => nil },
|
10
|
+
'snap2' => nil,
|
11
|
+
'snap3' => { 'snap3sub1' => nil ,
|
12
|
+
'snap3sub2' => nil ,
|
13
|
+
'snap3sub3' => nil } } }
|
14
|
+
let( :vms ) { [ MockRbVmomiVM.new( 'mockvm1', snaplist ),
|
15
|
+
MockRbVmomiVM.new( 'mockvm2', snaplist ),
|
16
|
+
MockRbVmomiVM.new( 'mockvm3', snaplist ) ] }
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
before :each do
|
21
|
+
stub_const( "RbVmomi", MockRbVmomi )
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#load_config" do
|
25
|
+
|
26
|
+
it 'can load a .fog file' do
|
27
|
+
File.stub( :exists? ).and_return( true )
|
28
|
+
YAML.stub( :load_file ).and_return( fog_file_contents )
|
29
|
+
|
30
|
+
expect( VsphereHelper.load_config ).to be === vInfo
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'raises an error when the .fog file is missing' do
|
35
|
+
File.stub( :exists? ).and_return( false )
|
36
|
+
|
37
|
+
expect{ VsphereHelper.load_config }.to raise_error( ArgumentError )
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#find_snapshot" do
|
44
|
+
it 'can find a given snapshot name' do
|
45
|
+
mockvm = MockRbVmomiVM.new( 'mockvm', snaplist )
|
46
|
+
|
47
|
+
expect( vsphere_helper.find_snapshot( mockvm, 'snap2' ) ).to be === mockvm.get_snapshot( 'snap2' )
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#find_customization" do
|
54
|
+
it 'returns the customization spec' do
|
55
|
+
|
56
|
+
expect( vsphere_helper.find_customization( 'name' ) ).to be === true
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#find_vms" do
|
63
|
+
it 'finds the list of vms' do
|
64
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
65
|
+
connection.set_info( vms )
|
66
|
+
|
67
|
+
expect( vsphere_helper.find_vms( 'mockvm1' ) ).to be === {vms[0].name => vms[0]}
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns {} when no vm is found' do
|
71
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
72
|
+
connection.set_info( vms )
|
73
|
+
|
74
|
+
expect( vsphere_helper.find_vms( 'novm' ) ).to be === {}
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#find_datastore" do
|
80
|
+
it 'finds the datastore from the connection object' do
|
81
|
+
expect(vsphere_helper.find_datastore( 'datastorename' ) ).to be === true
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#find_folder" do
|
87
|
+
it 'can find a folder in the datacenter' do
|
88
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
89
|
+
|
90
|
+
expect(vsphere_helper.find_folder( 'root' ) ).to be === connection.serviceInstance.find_datacenter.vmFolder
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#find_pool" do
|
96
|
+
it 'can find a pool in a folder in the datacenter' do
|
97
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
98
|
+
connection.serviceInstance.find_datacenter.hostFolder = MockRbVmomi::VIM::Folder.new
|
99
|
+
connection.serviceInstance.find_datacenter.hostFolder.name = "/root"
|
100
|
+
|
101
|
+
expect(vsphere_helper.find_pool( 'root' ) ).to be === connection.serviceInstance.find_datacenter.hostFolder
|
102
|
+
|
103
|
+
end
|
104
|
+
it 'can find a pool in a clustercomputeresource in the datacenter' do
|
105
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
106
|
+
connection.serviceInstance.find_datacenter.hostFolder = MockRbVmomi::VIM::ClusterComputeResource.new
|
107
|
+
connection.serviceInstance.find_datacenter.hostFolder.name = "/root"
|
108
|
+
|
109
|
+
expect(vsphere_helper.find_pool( 'root' ) ).to be === connection.serviceInstance.find_datacenter.hostFolder
|
110
|
+
|
111
|
+
end
|
112
|
+
it 'can find a pool in a resourcepool in the datacenter' do
|
113
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
114
|
+
connection.serviceInstance.find_datacenter.hostFolder = MockRbVmomi::VIM::ResourcePool.new
|
115
|
+
connection.serviceInstance.find_datacenter.hostFolder.name = "/root"
|
116
|
+
|
117
|
+
expect(vsphere_helper.find_pool( 'root' ) ).to be === connection.serviceInstance.find_datacenter.hostFolder
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#wait_for_tasks" do
|
123
|
+
it "can wait for tasks to error" do
|
124
|
+
vsphere_helper.stub( :sleep ).and_return( true )
|
125
|
+
vms.each do |vm|
|
126
|
+
vm.info.state = 'error'
|
127
|
+
end
|
128
|
+
|
129
|
+
expect(vsphere_helper.wait_for_tasks( vms, 0, 5 ) ).to be === vms
|
130
|
+
end
|
131
|
+
|
132
|
+
it "can wait for tasks to succeed" do
|
133
|
+
vsphere_helper.stub( :sleep ).and_return( true )
|
134
|
+
vms.each do |vm|
|
135
|
+
vm.info.state = 'success'
|
136
|
+
end
|
137
|
+
|
138
|
+
expect(vsphere_helper.wait_for_tasks( vms, 0, 5 ) ).to be === vms
|
139
|
+
end
|
140
|
+
|
141
|
+
it "errors when tasks fail to error/success before timing out" do
|
142
|
+
vsphere_helper.stub( :sleep ).and_return( true )
|
143
|
+
vms.each do |vm|
|
144
|
+
vm.info.state = 'nope'
|
145
|
+
end
|
146
|
+
|
147
|
+
expect{ vsphere_helper.wait_for_tasks( vms, 0, 5 ) }.to raise_error
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#close" do
|
153
|
+
it 'closes the connection' do
|
154
|
+
connection = vsphere_helper.instance_variable_get( :@connection )
|
155
|
+
connection.should_receive( :close ).once
|
156
|
+
|
157
|
+
vsphere_helper.close
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
describe Vsphere do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
MockVsphereHelper.set_config( fog_file_contents )
|
8
|
+
MockVsphereHelper.set_vms( make_hosts() )
|
9
|
+
stub_const( "VsphereHelper", MockVsphereHelper )
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#provision" do
|
13
|
+
|
14
|
+
it 'provisions hosts' do
|
15
|
+
MockVsphereHelper.powerOff
|
16
|
+
vsphere = Beaker::Vsphere.new( make_hosts(), make_opts )
|
17
|
+
|
18
|
+
vsphere.provision
|
19
|
+
|
20
|
+
hosts = vsphere.instance_variable_get( :@vsphere_hosts )
|
21
|
+
hosts.each do |host|
|
22
|
+
expect( MockVsphereHelper.find_vm( host.name ).powerState ) == "poweredOn"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises an error if a vm is missing in Vsphere' do
|
28
|
+
MockVsphereHelper.powerOff
|
29
|
+
hosts = make_hosts()
|
30
|
+
hosts[0][:vmname] = 'unknown'
|
31
|
+
vsphere = Beaker::Vsphere.new( hosts, make_opts )
|
32
|
+
|
33
|
+
expect{ vsphere.provision }.to raise_error
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises an error if a vm does not have a given snapshot name' do
|
38
|
+
MockVsphereHelper.powerOff
|
39
|
+
hosts = make_hosts()
|
40
|
+
hosts[0]["snapshot"] = 'unknown'
|
41
|
+
vsphere = Beaker::Vsphere.new( hosts, make_opts )
|
42
|
+
|
43
|
+
expect{ vsphere.provision }.to raise_error
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#cleanup" do
|
50
|
+
|
51
|
+
it "cleans up" do
|
52
|
+
MockVsphereHelper.powerOn
|
53
|
+
vsphere = Beaker::Vsphere.new( make_hosts(), make_opts )
|
54
|
+
vsphere.cleanup
|
55
|
+
|
56
|
+
hosts = vsphere.instance_variable_get( :@vsphere_hosts )
|
57
|
+
hosts.each do |host|
|
58
|
+
expect( MockVsphereHelper.find_vm( host.name ).powerState ) == "poweredOff"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'raises an error if a vm is missing in Vsphere' do
|
63
|
+
MockVsphereHelper.powerOn
|
64
|
+
hosts = make_hosts()
|
65
|
+
hosts[0][:vmname] = 'unknown'
|
66
|
+
vsphere = Beaker::Vsphere.new( hosts, make_opts )
|
67
|
+
|
68
|
+
expect{ vsphere.cleanup }.to raise_error
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
describe CommandLineParser do
|
6
|
+
|
7
|
+
let(:parser) {Beaker::Options::CommandLineParser.new}
|
8
|
+
let(:test_opts) {["-h", "vcloud.cfg", "--debug", "--tests", "test.rb", "--help"]}
|
9
|
+
let(:full_opts) {["--hosts", "host.cfg", "--options", "opts_file", "--type", "pe", "--helper", "path_to_helper", "--load-path", "load_path", "--tests", "test1.rb,test2.rb,test3.rb", "--pre-suite", "pre_suite.rb", "--post-suite", "post_suite.rb", "--no-provision", "--preserve-hosts", "--root-keys", "--keyfile", "../.ssh/id_rsa", "--install", "gitrepopath", "-m", "module", "-q", "--no-xml", "--dry-run", "--no-ntp", "--repo-proxy", "--add-el-extras", "--config", "anotherfile.cfg", "--fail-mode", "fast", "--no-color"]}
|
10
|
+
|
11
|
+
it "can correctly read command line input" do
|
12
|
+
expect(parser.parse!(test_opts)).to be === {:hosts_file=>"vcloud.cfg", :debug=>true, :tests=>"test.rb", :help=>true}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "supports all our command line options" do
|
16
|
+
expect(parser.parse!(full_opts)).to be === {:hosts_file=>"anotherfile.cfg", :options_file=>"opts_file", :type=>"pe", :helper=>"path_to_helper", :load_path=>"load_path", :tests=>"test1.rb,test2.rb,test3.rb", :pre_suite=>"pre_suite.rb", :post_suite=>"post_suite.rb", :provision=>false, :preserve_hosts=>true, :root_keys=>true, :keyfile=>"../.ssh/id_rsa", :install=>"gitrepopath", :modules=>"module", :quiet=>true, :xml=>false, :dry_run=>true, :timesync=>false, :repo_proxy=>true, :add_el_extras=>true, :fail_mode=>"fast", :color=>false}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can produce a usage description" do
|
20
|
+
expect{parser.usage}.to_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
HOSTS:
|
2
|
+
pe-ubuntu-lucid:
|
3
|
+
roles:
|
4
|
+
- agent
|
5
|
+
- dashboard
|
6
|
+
- database
|
7
|
+
- master
|
8
|
+
vmname : pe-ubuntu-lucid
|
9
|
+
platform: ubuntu-10.04-i386
|
10
|
+
snapshot : clean-w-keys
|
11
|
+
hypervisor : fusion
|
12
|
+
pe-centos6:
|
13
|
+
roles:
|
14
|
+
- agent
|
15
|
+
vmname : pe-centos6
|
16
|
+
platform: el-6-i386
|
17
|
+
hypervisor : fusion
|
18
|
+
snapshot *** clean-w-keys
|
19
|
+
CONFIG:
|
20
|
+
nfs_server: none
|
21
|
+
consoleport: 443
|
@@ -0,0 +1,21 @@
|
|
1
|
+
HOSTS:
|
2
|
+
pe-ubuntu-lucid:
|
3
|
+
roles:
|
4
|
+
- agent
|
5
|
+
- dashboard
|
6
|
+
- database
|
7
|
+
- master
|
8
|
+
vmname : pe-ubuntu-lucid
|
9
|
+
platform: ubuntu-10.04-i386
|
10
|
+
snapshot : clean-w-keys
|
11
|
+
hypervisor : fusion
|
12
|
+
pe-centos6:
|
13
|
+
roles:
|
14
|
+
- agent
|
15
|
+
vmname : pe-centos6
|
16
|
+
platform: el-6-i386
|
17
|
+
hypervisor : fusion
|
18
|
+
snapshot: clean-w-keys
|
19
|
+
CONFIG:
|
20
|
+
nfs_server: none
|
21
|
+
consoleport: 443
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
describe HostsFileParser do
|
6
|
+
|
7
|
+
let(:parser) {HostsFileParser}
|
8
|
+
let(:filepath) {File.join(File.expand_path(File.dirname(__FILE__)), "data", "hosts.cfg")}
|
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
|
15
|
+
|
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
|
22
|
+
|
23
|
+
it "raises an error on no file found" do
|
24
|
+
FakeFS.deactivate!
|
25
|
+
expect{parser.parse_hosts_file("not a valid path")}.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
describe OptionsFileParser do
|
6
|
+
|
7
|
+
let(:parser) {Beaker::Options::OptionsFileParser}
|
8
|
+
let(:simple_opts) {File.join(File.expand_path(File.dirname(__FILE__)), "data", "opts.txt")}
|
9
|
+
|
10
|
+
it "can correctly read options from a file" do
|
11
|
+
FakeFS.deactivate!
|
12
|
+
expect(parser.parse_options_file(simple_opts)).to be === {:debug=>true, :tests=>"test.rb", :pre_suite=>["pre-suite.rb"], :post_suite=>"post_suite1.rb,post_suite2.rb"}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "raises an error on no file found" do
|
16
|
+
FakeFS.deactivate!
|
17
|
+
expect{parser.parse_options_file("not a valid path")}.to raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
describe OptionsHash do
|
6
|
+
let(:options) { Beaker::Options::OptionsHash.new }
|
7
|
+
|
8
|
+
#test options hash methods
|
9
|
+
it "converts all string keys to symbols when doing direct assignment" do
|
10
|
+
options['key'] = 'value'
|
11
|
+
expect(options.has_key?(:key)) === true and expect(options.has_key?('key')) === false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can look up by string or symbol key" do
|
15
|
+
options.merge({'key' => 'value'})
|
16
|
+
expect(options['key']) === 'value' and expect(options[:key]) === 'value'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "supports is_pe?, defaults to pe" do
|
20
|
+
expect(options.is_pe?) === true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "supports is_pe?, respects :type == foss" do
|
24
|
+
options[:type] = 'foss'
|
25
|
+
expect(options.is_pe?) === false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can delete by string of symbol key" do
|
29
|
+
options['key'] = 'value'
|
30
|
+
expect(options.delete('key')) === 'value' and expect(options.delete(:key)) === 'value'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "when merged with a Hash remains an OptionsHash" do
|
34
|
+
options.merge({'key' => 'value'})
|
35
|
+
expect(options.is_a?(OptionsHash)) === true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "when merged with a hash that contains a hash, the sub-hash becomes an OptionsHash" do
|
39
|
+
options.merge({'key' => {'subkey' => 'subvalue'}})
|
40
|
+
expect(options[:key].is_a?(OptionsHash)) === true and expect(options[:key][:subkey]) === 'subvalue'
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'pretty prints itself' do
|
44
|
+
|
45
|
+
it 'in valid JSON' do
|
46
|
+
require 'json'
|
47
|
+
|
48
|
+
options['array'] = ['one', 'two', 'three']
|
49
|
+
options['hash'] = {'subkey' => { 'subsub' => 1 }}
|
50
|
+
options['nil'] = nil
|
51
|
+
options['number'] = 4
|
52
|
+
options['float'] = 1.0
|
53
|
+
options['string'] = 'string'
|
54
|
+
options['true'] = true
|
55
|
+
|
56
|
+
expect{ JSON.parse( options.dump ) }.to_not raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'for non collection values shows' do
|
60
|
+
it 'non-string like values as bare words' do
|
61
|
+
expect( options.fmt_value( 4 ) ).to be == "4"
|
62
|
+
expect( options.fmt_value( 1.0 ) ).to be == "1.0"
|
63
|
+
expect( options.fmt_value( true ) ).to be == "true"
|
64
|
+
expect( options.fmt_value( false ) ).to be == "false"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'nil values as null' do
|
68
|
+
expect( options.fmt_value( nil ) ).to be == 'null'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'strings within double quotes' do
|
72
|
+
expect( options.fmt_value( 'thing' ) ).to be == '"thing"'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'for list like collections shows' do
|
77
|
+
it 'each element on a new line' do
|
78
|
+
fmt_list = options.fmt_value( %w{ one two three } )
|
79
|
+
|
80
|
+
expect( fmt_list ).to match(/^\s*"one",?$/)
|
81
|
+
expect( fmt_list ).to match(/^\s*"two",?$/)
|
82
|
+
expect( fmt_list ).to match(/^\s*"three",?$/)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'square brackets on either end of the list' do
|
86
|
+
fmt_list = options.fmt_value( %w{ one two three } )
|
87
|
+
|
88
|
+
expect( fmt_list ).to match( /\A\[\s*$/ )
|
89
|
+
expect( fmt_list ).to match( /^\s*\]\Z/ )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'for dict like collections shows' do
|
94
|
+
it 'each element on a new line' do
|
95
|
+
fmt_assoc = options.fmt_value( {:one => 'two', :two => 'three'} )
|
96
|
+
|
97
|
+
expect( fmt_assoc ).to match(/^\s*"one": "two",?$/)
|
98
|
+
expect( fmt_assoc ).to match(/^\s*"two": "three",?$/)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'curly braces on either end of the list' do
|
102
|
+
fmt_assoc = options.fmt_value( {:one => 'two', :two => 'three'} )
|
103
|
+
|
104
|
+
expect( fmt_assoc ).to match( /\A\{\s*$/ )
|
105
|
+
expect( fmt_assoc ).to match( /^\s*\}\Z/ )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|