2011-06-29 22:21:55 +02:00
require 'spec_helper'
2015-06-01 13:21:59 +02:00
describe 'range' do
it { is_expected . not_to eq ( nil ) }
2011-06-29 22:21:55 +02:00
2015-06-01 13:21:59 +02:00
describe 'signature validation in puppet3' , :unless = > RSpec . configuration . puppet_future do
it { is_expected . to run . with_params ( ) . and_raise_error ( Puppet :: ParseError , / wrong number of arguments /i ) }
it {
pending ( " Current implementation ignores parameters after the third. " )
is_expected . to run . with_params ( 1 , 2 , 3 , 4 ) . and_raise_error ( Puppet :: ParseError , / wrong number of arguments /i )
}
it { is_expected . to run . with_params ( '1..2..3' ) . and_raise_error ( Puppet :: ParseError , / Unable to compute range /i ) }
it { is_expected . to run . with_params ( '' ) . and_raise_error ( Puppet :: ParseError , / Unknown range format /i ) }
2011-06-29 22:21:55 +02:00
end
2015-06-01 13:21:59 +02:00
describe 'signature validation in puppet4' , :if = > RSpec . configuration . puppet_future do
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( '' ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( { } ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( [ ] ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( true ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( true ) . and_raise_error ( ArgumentError ) }
it { is_expected . to run . with_params ( 1 , 2 , 'foo' ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( 1 , 2 , [ ] ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( 1 , 2 , { } ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( 1 , 2 , true ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( 1 , 2 , 3 , 4 ) . and_raise_error ( ArgumentError ) }
it { pending " the puppet 4 implementation " ; is_expected . to run . with_params ( '1..2..3' ) . and_raise_error ( ArgumentError ) }
2011-06-29 22:21:55 +02:00
end
2015-06-01 13:21:59 +02:00
context 'with characters as bounds' do
it { is_expected . to run . with_params ( 'd' , 'a' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( 'a' , 'a' ) . and_return ( [ 'a' ] ) }
it { is_expected . to run . with_params ( 'a' , 'b' ) . and_return ( [ 'a' , 'b' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' ) . and_return ( [ 'a' , 'b' , 'c' , 'd' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , 1 ) . and_return ( [ 'a' , 'b' , 'c' , 'd' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , '1' ) . and_return ( [ 'a' , 'b' , 'c' , 'd' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , 2 ) . and_return ( [ 'a' , 'c' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , - 2 ) . and_return ( [ 'a' , 'c' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , 3 ) . and_return ( [ 'a' , 'd' ] ) }
it { is_expected . to run . with_params ( 'a' , 'd' , 4 ) . and_return ( [ 'a' ] ) }
2012-04-03 17:46:20 +02:00
end
2015-06-01 13:21:59 +02:00
context 'with strings as bounds' do
it { is_expected . to run . with_params ( 'onea' , 'oned' ) . and_return ( [ 'onea' , 'oneb' , 'onec' , 'oned' ] ) }
it { is_expected . to run . with_params ( 'two' , 'one' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( 'true' , 'false' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( 'false' , 'true' ) . and_return ( [ 'false' ] ) }
end
2011-07-24 01:39:17 +02:00
2015-06-01 13:21:59 +02:00
context 'with integers as bounds' do
it { is_expected . to run . with_params ( 4 , 1 ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( 1 , 1 ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( 1 , 2 ) . and_return ( [ 1 , 2 ] ) }
it { is_expected . to run . with_params ( 1 , 4 ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , 1 ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , '1' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , 2 ) . and_return ( [ 1 , 3 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , - 2 ) . and_return ( [ 1 , 3 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , 3 ) . and_return ( [ 1 , 4 ] ) }
it { is_expected . to run . with_params ( 1 , 4 , 4 ) . and_return ( [ 1 ] ) }
end
2012-03-30 00:12:06 +02:00
2015-06-01 13:21:59 +02:00
context 'with integers as strings as bounds' do
it { is_expected . to run . with_params ( '4' , '1' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( '1' , '1' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( '1' , '2' ) . and_return ( [ 1 , 2 ] ) }
it { is_expected . to run . with_params ( '1' , '4' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , 1 ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , '1' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , 2 ) . and_return ( [ 1 , 3 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , - 2 ) . and_return ( [ 1 , 3 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , 3 ) . and_return ( [ 1 , 4 ] ) }
it { is_expected . to run . with_params ( '1' , '4' , 4 ) . and_return ( [ 1 ] ) }
end
2013-05-28 20:03:51 +02:00
2015-06-01 13:21:59 +02:00
context 'with prefixed numbers as strings as bounds' do
it { is_expected . to run . with_params ( 'host01' , 'host04' ) . and_return ( [ 'host01' , 'host02' , 'host03' , 'host04' ] ) }
it { is_expected . to run . with_params ( '01' , '04' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
2012-04-03 17:46:20 +02:00
end
2015-06-01 13:21:59 +02:00
context 'with dash-range syntax' do
it { is_expected . to run . with_params ( '4-1' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( '1-1' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( '1-2' ) . and_return ( [ 1 , 2 ] ) }
it { is_expected . to run . with_params ( '1-4' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
end
2012-04-03 17:46:20 +02:00
2015-06-01 13:21:59 +02:00
context 'with two-dot-range syntax' do
it { is_expected . to run . with_params ( '4..1' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( '1..1' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( '1..2' ) . and_return ( [ 1 , 2 ] ) }
it { is_expected . to run . with_params ( '1..4' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
2012-04-03 17:46:20 +02:00
end
2014-11-12 16:02:05 +01:00
2015-06-01 13:21:59 +02:00
context 'with three-dot-range syntax' do
it { is_expected . to run . with_params ( '4...1' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( '1...1' ) . and_return ( [ ] ) }
it { is_expected . to run . with_params ( '1...2' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( '1...3' ) . and_return ( [ 1 , 2 ] ) }
it { is_expected . to run . with_params ( '1...5' ) . and_return ( [ 1 , 2 , 3 , 4 ] ) }
2015-05-06 11:13:27 +02:00
end
2015-06-01 13:21:59 +02:00
describe 'when passing mixed arguments as bounds' do
it {
pending ( 'these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially' )
is_expected . to run . with_params ( '0' , 'a' ) . and_raise_error ( Puppet :: ParseError , / cannot interpolate between numeric and non-numeric bounds / )
}
it {
pending ( 'these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially' )
is_expected . to run . with_params ( 0 , 'a' ) . and_raise_error ( Puppet :: ParseError , / cannot interpolate between numeric and non-numeric bounds / )
}
it {
pending ( 'these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially' )
is_expected . to run . with_params ( 'h0' , 'ha' ) . and_raise_error ( Puppet :: ParseError , / cannot interpolate between numeric and non-numeric bounds / )
}
2014-11-12 16:02:05 +01:00
end
2011-06-29 22:21:55 +02:00
end