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_ip_address 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
|
2011-08-05 09:25:03 +02:00
|
|
|
Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise a ParseError if there is less than 1 arguments" do
|
2012-07-20 01:14:37 +02:00
|
|
|
lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2011-07-28 19:10:16 +02:00
|
|
|
it "should return true if an IPv4 address" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_is_ip_address(["1.2.3.4"])
|
2011-07-28 19:10:16 +02:00
|
|
|
result.should(eq(true))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if a full IPv6 address" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
|
2011-07-28 19:10:16 +02:00
|
|
|
result.should(eq(true))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if a compressed IPv6 address" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_is_ip_address(["fe00::1"])
|
2011-07-24 01:39:17 +02:00
|
|
|
result.should(eq(true))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if not valid" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_is_ip_address(["asdf"])
|
2011-07-24 01:39:17 +02:00
|
|
|
result.should(eq(false))
|
|
|
|
end
|
|
|
|
|
2011-07-28 19:10:16 +02:00
|
|
|
it "should return false if IP octets out of range" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_is_ip_address(["1.1.1.300"])
|
2011-07-28 19:10:16 +02:00
|
|
|
result.should(eq(false))
|
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|