comparison modules/stdlib/spec/functions/is_domain_name_spec.rb @ 37:addb0ea390a1 puppet-3.6

Update Puppet "stdlib" module
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Mar 2015 20:09:45 +0000
parents
children c42fb28cff86
comparison
equal deleted inserted replaced
36:37675581a273 37:addb0ea390a1
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 end