spec/beaker/options/parser_spec.rb in beaker-2.14.1 vs spec/beaker/options/parser_spec.rb in beaker-2.15.0
- old
+ new
@@ -135,18 +135,84 @@
FakeFS.deactivate!
expect{parser.check_yaml_file("not a path")}.to raise_error(ArgumentError)
end
end
- describe 'parse_args' do
+ describe '#parse_args' do
before { FakeFS.deactivate! }
it 'pulls the args into key called :command_line' do
my_args = [ '--log-level', 'debug', '-h', hosts_path]
expect(parser.parse_args( my_args )[:command_line]).to include(my_args.join(' '))
end
+ describe 'does prioritization correctly' do
+ let(:env) { @env || {:level => 'highest'} }
+ let(:argv) { @argv || {:level => 'second'} }
+ let(:host_file) { @host_file || {:level => 'third'} }
+ let(:opt_file) { @opt_file || {:level => 'fourth' } }
+ let(:presets) { {:level => 'lowest' } }
+
+ before :each do
+ expect(parser).to receive( :normalize_args ).and_return( true )
+ end
+
+ def mock_out_parsing
+ presets_obj = double()
+ allow( presets_obj ).to receive( :presets ).and_return( presets )
+ allow( presets_obj ).to receive( :env_vars ).and_return( env )
+ parser.instance_variable_set( :@presets, presets_obj )
+
+ command_line_parser_obj = double()
+ allow( command_line_parser_obj ).to receive( :parse ).and_return( argv )
+ parser.instance_variable_set( :@command_line_parser, command_line_parser_obj )
+
+ allow( OptionsFileParser ).to receive( :parse_options_file ).and_return( opt_file )
+ allow( HostsFileParser ).to receive( :parse_hosts_file ).and_return( host_file )
+ end
+
+ it 'presets have the lowest priority' do
+ @env = @argv = @host_file = @opt_file = {}
+ mock_out_parsing
+
+ opts = parser.parse_args([])
+ expect( opts[:level] ).to be == 'lowest'
+ end
+
+ it 'options file has fourth priority' do
+ @env = @argv = @host_file = {}
+ mock_out_parsing
+
+ opts = parser.parse_args([])
+ expect( opts[:level] ).to be == 'fourth'
+ end
+
+ it 'host file CONFIG section has third priority' do
+ @env = @argv = {}
+ mock_out_parsing
+
+ opts = parser.parse_args([])
+ expect( opts[:level] ).to be == 'third'
+ end
+
+ it 'command line arguments have second priority' do
+ @env = {}
+ mock_out_parsing
+
+ opts = parser.parse_args([])
+ expect( opts[:level] ).to be == 'second'
+ end
+
+ it 'env vars have highest priority' do
+ mock_out_parsing
+
+ opts = parser.parse_args([])
+ expect( opts[:level] ).to be == 'highest'
+ end
+
+ end
+
it "can correctly combine arguments from different sources" do
build_url = 'http://my.build.url/'
type = 'git'
log_level = 'debug'
@@ -274,9 +340,68 @@
parser.normalize_args
expect( hosts['HOSTS'][:master][:user] ).to be == 'root'
end
end
+ end
+
+ describe '#normalize_and_validate_tags' do
+ let ( :tag_includes ) { @tag_includes || [] }
+ let ( :tag_excludes ) { @tag_excludes || [] }
+ let ( :options ) {
+ opts = Beaker::Options::OptionsHash.new
+ opts[:tag_includes] = tag_includes
+ opts[:tag_excludes] = tag_excludes
+ opts
+ }
+
+ it 'does not error if no tags overlap' do
+ @tag_includes = 'can,tommies,potatoes,plant'
+ @tag_excludes = 'joey,long_running,pants'
+ parser.instance_variable_set(:@options, options)
+
+ expect( parser ).to_not receive( :parser_error )
+ parser.normalize_and_validate_tags()
+ end
+
+ it 'does error if tags overlap' do
+ @tag_includes = 'can,tommies,should_error,potatoes,plant'
+ @tag_excludes = 'joey,long_running,pants,should_error'
+ parser.instance_variable_set(:@options, options)
+
+ expect( parser ).to receive( :parser_error )
+ parser.normalize_and_validate_tags()
+ end
+
+ it 'splits the basic case correctly' do
+ @tag_includes = 'can,tommies,potatoes,plant'
+ @tag_excludes = 'joey,long_running,pants'
+ parser.instance_variable_set(:@options, options)
+
+ parser.normalize_and_validate_tags()
+ expect( options[:tag_includes] ).to be === ['can', 'tommies', 'potatoes', 'plant']
+ expect( options[:tag_excludes] ).to be === ['joey', 'long_running', 'pants']
+ end
+
+ it 'returns empty arrays for empty strings' do
+ @tag_includes = ''
+ @tag_excludes = ''
+ parser.instance_variable_set(:@options, options)
+
+ parser.normalize_and_validate_tags()
+ expect( options[:tag_includes] ).to be === []
+ expect( options[:tag_excludes] ).to be === []
+ end
+
+ it 'lowercases all tags correctly for later use' do
+ @tag_includes = 'jeRRy_And_tOM,PARka'
+ @tag_excludes = 'lEet_spEAK,pOland'
+ parser.instance_variable_set(:@options, options)
+
+ parser.normalize_and_validate_tags()
+ expect( options[:tag_includes] ).to be === ['jerry_and_tom', 'parka']
+ expect( options[:tag_excludes] ).to be === ['leet_speak', 'poland']
+ end
end
end
end
end