1 #! /usr/bin/env ruby -S rspec
4 describe "the is_domain_name function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name")
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))
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)
20 it "should return true if the domain is ." do
21 result = scope.function_is_domain_name(["."])
22 expect(result).to(be_truthy)
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)
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)
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)
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)
45 it "should allow a single part domain" do
46 result = scope.function_is_domain_name(["orange"])
47 expect(result).to(be_truthy)
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)
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)
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)
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)
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)
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)