Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_domain_name_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_domain_name' 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('com', 'com.') }
11     it { is_expected.to run.with_params('x.com', 'x.com.') }
12     it { is_expected.to run.with_params('foo.example.com', 'foo.example.com.') }
13     it { is_expected.to run.with_params('2foo.example.com', '2foo.example.com.') }
14     it { is_expected.to run.with_params('www.2foo.example.com', 'www.2foo.example.com.') }
15     it { is_expected.to run.with_params('domain.tld', 'puppet.com') }
16   end
17
18   describe 'invalid inputs' do
19     it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a string}) }
20     it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
21     it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
22     it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
23
24     it { is_expected.to run.with_params('foo.example.com', []).and_raise_error(Puppet::ParseError, %r{is not a string}) }
25     it { is_expected.to run.with_params('foo.example.com', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
26     it { is_expected.to run.with_params('foo.example.com', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
27     it { is_expected.to run.with_params('foo.example.com', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
28
29     it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
30     it { is_expected.to run.with_params('invalid domain').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
31     it { is_expected.to run.with_params('-foo.example.com').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
32     it { is_expected.to run.with_params('www.example.2com').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
33     it { is_expected.to run.with_params('192.168.1.1').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
34   end
35 end