8fd145eb6bd6b32eda92250c6a110e309ed6af0c
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_ip_address_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_ip_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   describe 'valid inputs' do
10     it { is_expected.to run.with_params('0.0.0.0') }
11     it { is_expected.to run.with_params('8.8.8.8') }
12     it { is_expected.to run.with_params('127.0.0.1') }
13     it { is_expected.to run.with_params('10.10.10.10') }
14     it { is_expected.to run.with_params('194.232.104.150') }
15     it { is_expected.to run.with_params('244.24.24.24') }
16     it { is_expected.to run.with_params('255.255.255.255') }
17     it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') }
18     it { is_expected.to run.with_params('3ffe:0505:0002::') }
19     it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
20     it { is_expected.to run.with_params('::1/64') }
21     it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
22
23     context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
24       after(:each) do
25         ENV.delete('STDLIB_LOG_DEPRECATIONS')
26       end
27       # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
28       it 'displays a single deprecation' do
29         ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
30         expect(scope).to receive(:warning).with(include('This method is deprecated'))
31         is_expected.to run.with_params('1.2.3.4')
32       end
33       it 'displays no warning for deprecation' do
34         ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
35         expect(scope).to receive(:warning).with(include('This method is deprecated')).never
36         is_expected.to run.with_params('1.2.3.4')
37       end
38     end
39
40     context 'with netmasks' do
41       it { is_expected.to run.with_params('8.8.8.8/0') }
42       it { is_expected.to run.with_params('8.8.8.8/16') }
43       it { is_expected.to run.with_params('8.8.8.8/32') }
44       it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') }
45     end
46   end
47
48   describe 'invalid inputs' do
49     it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
50     it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
51     it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
52     it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
53     it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
54     it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
55     it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
56     it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
57     it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
58     it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
59     it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
60     it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
61     it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
62     it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
63   end
64 end