Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / is_domain_name_spec.rb
1 require 'spec_helper'
2
3 describe 'is_domain_name' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
6   it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
7   it { is_expected.to run.with_params(1).and_return(false) }
8   it { is_expected.to run.with_params([]).and_return(false) }
9   it { is_expected.to run.with_params({}).and_return(false) }
10   it { is_expected.to run.with_params('').and_return(false) }
11   it { is_expected.to run.with_params('.').and_return(true) }
12   it { is_expected.to run.with_params('com').and_return(true) }
13   it { is_expected.to run.with_params('com.').and_return(true) }
14   it { is_expected.to run.with_params('x.com').and_return(true) }
15   it { is_expected.to run.with_params('x.com.').and_return(true) }
16   it { is_expected.to run.with_params('foo.example.com').and_return(true) }
17   it { is_expected.to run.with_params('foo.example.com.').and_return(true) }
18   it { is_expected.to run.with_params('2foo.example.com').and_return(true) }
19   it { is_expected.to run.with_params('2foo.example.com.').and_return(true) }
20   it { is_expected.to run.with_params('www.2foo.example.com').and_return(true) }
21   it { is_expected.to run.with_params('www.2foo.example.com.').and_return(true) }
22   it { is_expected.to run.with_params(true).and_return(false) }
23
24   describe 'inputs with spaces' do
25     it { is_expected.to run.with_params('invalid domain').and_return(false) }
26   end
27
28   describe 'inputs with hyphens' do
29     it { is_expected.to run.with_params('foo-bar.example.com').and_return(true) }
30     it { is_expected.to run.with_params('foo-bar.example.com.').and_return(true) }
31     it { is_expected.to run.with_params('www.foo-bar.example.com').and_return(true) }
32     it { is_expected.to run.with_params('www.foo-bar.example.com.').and_return(true) }
33     it { is_expected.to run.with_params('-foo.example.com').and_return(false) }
34     it { is_expected.to run.with_params('-foo.example.com.').and_return(false) }
35   end
36
37   # Values obtained from Facter values will be frozen strings
38   # in newer versions of Facter:
39   it { is_expected.to run.with_params('www.example.com'.freeze).and_return(true) }
40
41   describe 'top level domain must be alphabetic if there are multiple labels' do
42     it { is_expected.to run.with_params('2com').and_return(true) }
43     it { is_expected.to run.with_params('www.example.2com').and_return(false) }
44   end
45
46   describe 'IP addresses are not domain names' do
47     it { is_expected.to run.with_params('192.168.1.1').and_return(false) }
48   end
49 end