2012-07-20 00:27:52 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-06-29 22:21:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-08-05 09:25:03 +02:00
|
|
|
describe "the is_domain_name function" do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
it "should exist" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name")
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise a ParseError if there is less than 1 arguments" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_is_domain_name([]) }.to( raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2012-01-12 04:15:04 +01:00
|
|
|
it "should return true if a valid short domain name" do
|
|
|
|
result = scope.function_is_domain_name(["x.com"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2012-01-12 04:15:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if the domain is ." do
|
|
|
|
result = scope.function_is_domain_name(["."])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2012-01-12 04:15:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if the domain is x.com." do
|
|
|
|
result = scope.function_is_domain_name(["x.com."])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2012-01-12 04:15:04 +01:00
|
|
|
end
|
|
|
|
|
2011-07-24 01:39:17 +02:00
|
|
|
it "should return true if a valid domain name" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["foo.bar.com"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
|
|
|
|
2011-07-29 21:08:31 +02:00
|
|
|
it "should allow domain parts to start with numbers" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["3foo.2bar.com"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-29 21:08:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow domain to end with a dot" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["3foo.2bar.com."])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-29 21:08:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow a single part domain" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["orange"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-29 21:08:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if domain parts start with hyphens" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["-3foo.2bar.com"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2011-07-29 21:08:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if domain contains hyphens" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-29 21:08:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if domain name contains spaces" do
|
2012-01-12 03:55:21 +01:00
|
|
|
result = scope.function_is_domain_name(["not valid"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
2015-02-14 16:46:34 +01:00
|
|
|
|
|
|
|
# Values obtained from Facter values will be frozen strings
|
|
|
|
# in newer versions of Facter:
|
|
|
|
it "should not throw an exception if passed a frozen string" do
|
|
|
|
result = scope.function_is_domain_name(["my.domain.name".freeze])
|
|
|
|
expect(result).to(be_truthy)
|
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|