Update stdlib
[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
5   describe 'signature validation' do
6     it { is_expected.not_to eq(nil) }
7     it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
8   end
9
10   context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
11     after(:all) do
12       ENV.delete('STDLIB_LOG_DEPRECATIONS')
13     end
14     # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
15     it 'should display a single deprecation' do
16       ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
17       scope.expects(:warning).with(includes('This method is deprecated'))
18       is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
19     end
20     it 'should display no warning for deprecation' do
21       ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
22       scope.expects(:warning).with(includes('This method is deprecated')).never
23       is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
24     end
25   end
26
27   SharedData::IPV4_PATTERNS.each do |value|
28     it { is_expected.to run.with_params(value) }
29   end
30
31   SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
32     it { is_expected.to run.with_params(value).and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
33   end
34
35   describe 'invalid inputs' do
36     [ {}, [], 1, true ].each do |invalid|
37       it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, /is not a string/) }
38       it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first, invalid).and_raise_error(Puppet::ParseError, /is not a string/) }
39     end
40   end
41 end