]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/is_domain_name_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / is_domain_name_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the is_domain_name function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name")
9   end
10
11   it "should raise a ParseError if there is less than 1 arguments" do
12     expect { scope.function_is_domain_name([]) }.to( raise_error(Puppet::ParseError))
13   end
14
15   it "should return true if a valid short domain name" do
16     result = scope.function_is_domain_name(["x.com"])
17     expect(result).to(be_truthy)
18   end
19
20   it "should return true if the domain is ." do
21     result = scope.function_is_domain_name(["."])
22     expect(result).to(be_truthy)
23   end
24
25   it "should return true if the domain is x.com." do
26     result = scope.function_is_domain_name(["x.com."])
27     expect(result).to(be_truthy)
28   end
29
30   it "should return true if a valid domain name" do
31     result = scope.function_is_domain_name(["foo.bar.com"])
32     expect(result).to(be_truthy)
33   end
34
35   it "should allow domain parts to start with numbers" do
36     result = scope.function_is_domain_name(["3foo.2bar.com"])
37     expect(result).to(be_truthy)
38   end
39
40   it "should allow domain to end with a dot" do
41     result = scope.function_is_domain_name(["3foo.2bar.com."])
42     expect(result).to(be_truthy)
43   end
44
45   it "should allow a single part domain" do
46     result = scope.function_is_domain_name(["orange"])
47     expect(result).to(be_truthy)
48   end
49
50   it "should return false if domain parts start with hyphens" do
51     result = scope.function_is_domain_name(["-3foo.2bar.com"])
52     expect(result).to(be_falsey)
53   end
54
55   it "should return true if domain contains hyphens" do
56     result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
57     expect(result).to(be_truthy)
58   end
59
60   it "should return false if domain name contains spaces" do
61     result = scope.function_is_domain_name(["not valid"])
62     expect(result).to(be_falsey)
63   end
64
65   # Values obtained from Facter values will be frozen strings
66   # in newer versions of Facter:
67   it "should not throw an exception if passed a frozen string" do
68     result = scope.function_is_domain_name(["my.domain.name".freeze])
69     expect(result).to(be_truthy)
70   end
71
72   it "should return false if top-level domain is not entirely alphabetic" do
73     result = scope.function_is_domain_name(["kiwi.2bar"])
74     expect(result).to(be_falsey)
75   end
76
77   it "should return false if domain name has the dotted-decimal form, e.g. an IPv4 address" do
78     result = scope.function_is_domain_name(["192.168.1.1"])
79     expect(result).to(be_falsey)
80   end
81 end