[30960] | 1 | require 'spec_helper'
|
---|
| 2 |
|
---|
| 3 | describe 'range' do
|
---|
| 4 | it { is_expected.not_to eq(nil) }
|
---|
| 5 |
|
---|
| 6 | describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do
|
---|
| 7 | it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
| 8 | it {
|
---|
| 9 | pending("Current implementation ignores parameters after the third.")
|
---|
| 10 | is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
|
---|
| 11 | }
|
---|
| 12 | it { is_expected.to run.with_params('1..2..3').and_raise_error(Puppet::ParseError, /Unable to compute range/i) }
|
---|
| 13 | it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /Unknown range format/i) }
|
---|
| 14 | end
|
---|
| 15 |
|
---|
| 16 | describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do
|
---|
| 17 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params().and_raise_error(ArgumentError) }
|
---|
| 18 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params('').and_raise_error(ArgumentError) }
|
---|
| 19 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params({}).and_raise_error(ArgumentError) }
|
---|
| 20 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params([]).and_raise_error(ArgumentError) }
|
---|
| 21 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) }
|
---|
| 22 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) }
|
---|
| 23 | it { is_expected.to run.with_params(1, 2, 'foo').and_raise_error(ArgumentError) }
|
---|
| 24 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, []).and_raise_error(ArgumentError) }
|
---|
| 25 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, {}).and_raise_error(ArgumentError) }
|
---|
| 26 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, true).and_raise_error(ArgumentError) }
|
---|
| 27 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(ArgumentError) }
|
---|
| 28 | it { pending "the puppet 4 implementation"; is_expected.to run.with_params('1..2..3').and_raise_error(ArgumentError) }
|
---|
| 29 | end
|
---|
| 30 |
|
---|
| 31 | context 'with characters as bounds' do
|
---|
| 32 | it { is_expected.to run.with_params('d', 'a').and_return([]) }
|
---|
| 33 | it { is_expected.to run.with_params('a', 'a').and_return(['a']) }
|
---|
| 34 | it { is_expected.to run.with_params('a', 'b').and_return(['a', 'b']) }
|
---|
| 35 | it { is_expected.to run.with_params('a', 'd').and_return(['a', 'b', 'c', 'd']) }
|
---|
| 36 | it { is_expected.to run.with_params('a', 'd', 1).and_return(['a', 'b', 'c', 'd']) }
|
---|
| 37 | it { is_expected.to run.with_params('a', 'd', '1').and_return(['a', 'b', 'c', 'd']) }
|
---|
| 38 | it { is_expected.to run.with_params('a', 'd', 2).and_return(['a', 'c']) }
|
---|
| 39 | it { is_expected.to run.with_params('a', 'd', -2).and_return(['a', 'c']) }
|
---|
| 40 | it { is_expected.to run.with_params('a', 'd', 3).and_return(['a', 'd']) }
|
---|
| 41 | it { is_expected.to run.with_params('a', 'd', 4).and_return(['a']) }
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | context 'with strings as bounds' do
|
---|
| 45 | it { is_expected.to run.with_params('onea', 'oned').and_return(['onea', 'oneb', 'onec', 'oned']) }
|
---|
| 46 | it { is_expected.to run.with_params('two', 'one').and_return([]) }
|
---|
| 47 | it { is_expected.to run.with_params('true', 'false').and_return([]) }
|
---|
| 48 | it { is_expected.to run.with_params('false', 'true').and_return(['false']) }
|
---|
| 49 | end
|
---|
| 50 |
|
---|
| 51 | context 'with integers as bounds' do
|
---|
| 52 | it { is_expected.to run.with_params(4, 1).and_return([]) }
|
---|
| 53 | it { is_expected.to run.with_params(1, 1).and_return([1]) }
|
---|
| 54 | it { is_expected.to run.with_params(1, 2).and_return([1, 2]) }
|
---|
| 55 | it { is_expected.to run.with_params(1, 4).and_return([1, 2, 3, 4]) }
|
---|
| 56 | it { is_expected.to run.with_params(1, 4, 1).and_return([1, 2, 3, 4]) }
|
---|
| 57 | it { is_expected.to run.with_params(1, 4, '1').and_return([1, 2, 3, 4]) }
|
---|
| 58 | it { is_expected.to run.with_params(1, 4, 2).and_return([1, 3]) }
|
---|
| 59 | it { is_expected.to run.with_params(1, 4, -2).and_return([1, 3]) }
|
---|
| 60 | it { is_expected.to run.with_params(1, 4, 3).and_return([1, 4]) }
|
---|
| 61 | it { is_expected.to run.with_params(1, 4, 4).and_return([1]) }
|
---|
| 62 | end
|
---|
| 63 |
|
---|
| 64 | context 'with integers as strings as bounds' do
|
---|
| 65 | it { is_expected.to run.with_params('4', '1').and_return([]) }
|
---|
| 66 | it { is_expected.to run.with_params('1', '1').and_return([1]) }
|
---|
| 67 | it { is_expected.to run.with_params('1', '2').and_return([1, 2]) }
|
---|
| 68 | it { is_expected.to run.with_params('1', '4').and_return([1, 2, 3, 4]) }
|
---|
| 69 | it { is_expected.to run.with_params('1', '4', 1).and_return([1, 2, 3, 4]) }
|
---|
| 70 | it { is_expected.to run.with_params('1', '4', '1').and_return([1, 2, 3, 4]) }
|
---|
| 71 | it { is_expected.to run.with_params('1', '4', 2).and_return([1, 3]) }
|
---|
| 72 | it { is_expected.to run.with_params('1', '4', -2).and_return([1, 3]) }
|
---|
| 73 | it { is_expected.to run.with_params('1', '4', 3).and_return([1, 4]) }
|
---|
| 74 | it { is_expected.to run.with_params('1', '4', 4).and_return([1]) }
|
---|
| 75 | end
|
---|
| 76 |
|
---|
| 77 | context 'with prefixed numbers as strings as bounds' do
|
---|
| 78 | it { is_expected.to run.with_params('host01', 'host04').and_return(['host01', 'host02', 'host03', 'host04']) }
|
---|
| 79 | it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) }
|
---|
| 80 | end
|
---|
| 81 |
|
---|
| 82 | context 'with dash-range syntax' do
|
---|
| 83 | it { is_expected.to run.with_params('4-1').and_return([]) }
|
---|
| 84 | it { is_expected.to run.with_params('1-1').and_return([1]) }
|
---|
| 85 | it { is_expected.to run.with_params('1-2').and_return([1, 2]) }
|
---|
| 86 | it { is_expected.to run.with_params('1-4').and_return([1, 2, 3, 4]) }
|
---|
| 87 | end
|
---|
| 88 |
|
---|
| 89 | context 'with two-dot-range syntax' do
|
---|
| 90 | it { is_expected.to run.with_params('4..1').and_return([]) }
|
---|
| 91 | it { is_expected.to run.with_params('1..1').and_return([1]) }
|
---|
| 92 | it { is_expected.to run.with_params('1..2').and_return([1, 2]) }
|
---|
| 93 | it { is_expected.to run.with_params('1..4').and_return([1, 2, 3, 4]) }
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | context 'with three-dot-range syntax' do
|
---|
| 97 | it { is_expected.to run.with_params('4...1').and_return([]) }
|
---|
| 98 | it { is_expected.to run.with_params('1...1').and_return([]) }
|
---|
| 99 | it { is_expected.to run.with_params('1...2').and_return([1]) }
|
---|
| 100 | it { is_expected.to run.with_params('1...3').and_return([1, 2]) }
|
---|
| 101 | it { is_expected.to run.with_params('1...5').and_return([1, 2, 3, 4]) }
|
---|
| 102 | end
|
---|
| 103 |
|
---|
| 104 | describe 'when passing mixed arguments as bounds' do
|
---|
| 105 | it {
|
---|
| 106 | 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')
|
---|
| 107 | is_expected.to run.with_params('0', 'a').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/)
|
---|
| 108 | }
|
---|
| 109 | it {
|
---|
| 110 | 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')
|
---|
| 111 | is_expected.to run.with_params(0, 'a').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/)
|
---|
| 112 | }
|
---|
| 113 | it {
|
---|
| 114 | 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')
|
---|
| 115 | is_expected.to run.with_params('h0', 'ha').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/)
|
---|
| 116 | }
|
---|
| 117 | end
|
---|
| 118 | end
|
---|