Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_ipv4_address_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_ipv4_address' do
4   describe 'signature validation' do
5     it { is_expected.not_to eq(nil) }
6     it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
7   end
8
9   context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
10     after(:each) do
11       ENV.delete('STDLIB_LOG_DEPRECATIONS')
12     end
13     # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
14     it 'displays a single deprecation' do
15       ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
16       expect(scope).to receive(:warning).with(include('This method is deprecated'))
17       is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
18     end
19     it 'displays no warning for deprecation' do
20       ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
21       expect(scope).to receive(:warning).with(include('This method is deprecated')).never
22       is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
23     end
24   end
25
26   SharedData::IPV4_PATTERNS.each do |value|
27     it { is_expected.to run.with_params(value) }
28   end
29
30   SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
31     it { is_expected.to run.with_params(value).and_raise_error(Puppet::ParseError, %r{is not a valid IPv4}) }
32   end
33
34   describe 'invalid inputs' do
35     [{}, [], 1, true].each do |invalid|
36       it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) }
37       it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first, invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) }
38     end
39   end
40
41   describe 'multiple inputs' do
42     it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS[0], SharedData::IPV4_PATTERNS[1]) }
43     it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS[0], 'invalid ip').and_raise_error(Puppet::ParseError, %r{is not a valid IPv4}) }
44   end
45 end