range_spec.rb 7.9 KB

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