2012-02-22 16:46:07 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'validate_slength' do
|
|
|
|
describe 'signature validation' do
|
|
|
|
it { is_expected.not_to eq(nil) }
|
|
|
|
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) }
|
|
|
|
it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) }
|
|
|
|
it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) }
|
|
|
|
it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) }
|
|
|
|
it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, /argument to be larger than third argument/) }
|
2012-02-22 16:46:07 +01:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context "with a maximum length of 10" do
|
|
|
|
describe 'rejects strings longer than the limit' do
|
|
|
|
it { is_expected.to run.with_params('1234567890a', 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
|
|
|
it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
|
|
|
it { is_expected.to run.with_params([ 'one', '1234567890abcdef' ], 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
2013-08-12 21:48:46 +02:00
|
|
|
end
|
2013-06-28 18:03:37 +02:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'accepts strings shorter or equal to the limit' do
|
|
|
|
it { is_expected.to run.with_params('1234567890', 10) }
|
|
|
|
it { is_expected.to run.with_params('12345', 10) }
|
|
|
|
it { is_expected.to run.with_params([ 'one', 'two' ], 10) }
|
2013-08-12 21:48:46 +02:00
|
|
|
end
|
2012-02-22 16:46:07 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context "with a minimum length of 5" do
|
|
|
|
describe 'rejects strings longer than the upper limit' do
|
|
|
|
it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
|
|
|
it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
2013-08-12 21:48:46 +02:00
|
|
|
end
|
2012-02-22 16:46:07 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'rejects numbers shorter than the lower limit' do
|
|
|
|
it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
|
|
|
it { is_expected.to run.with_params(['12345678', 'two'], 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
2013-08-12 21:48:46 +02:00
|
|
|
end
|
2012-02-22 16:46:07 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'accepts strings of length between and including the limits' do
|
|
|
|
it { is_expected.to run.with_params('12345', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params('123456', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params('1234567', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params('12345678', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params('123456789', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params('1234567890', 10, 5) }
|
|
|
|
it { is_expected.to run.with_params(['1233456', '12345678'], 10, 5) }
|
2013-08-12 21:48:46 +02:00
|
|
|
end
|
|
|
|
end
|
2015-06-01 13:21:59 +02:00
|
|
|
end
|
2012-02-22 16:46:07 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'corner cases' do
|
|
|
|
it { pending('this should work'); is_expected.to run.with_params('', 0, 0) }
|
|
|
|
it { is_expected.to run.with_params('1234567890', 10, 10) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'empty upper limit is interpreted as infinity' do
|
|
|
|
it { pending('not implemented'); is_expected.to run.with_params('1234567890ab', '', 10) }
|
|
|
|
it { pending('not implemented'); is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
2012-02-22 16:46:07 +01:00
|
|
|
end
|
|
|
|
end
|