summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorWill Farrington <wfarr@github.com>2013-05-22 17:10:45 -0700
committerWill Farrington <wfarr@github.com>2013-05-22 17:10:45 -0700
commitcf37a128a0939a6ba842d735a664b957905cbd87 (patch)
treeb0970885993a04af2b13a1c4d3a72d4ea923a915 /spec/unit
parent2cdbbafc06844afe7337717d9e29c720819d528c (diff)
downloadpuppet-stdlib-cf37a128a0939a6ba842d735a664b957905cbd87.tar.gz
puppet-stdlib-cf37a128a0939a6ba842d735a664b957905cbd87.tar.bz2
Add functions to validate ipv4 and ipv6 addresses
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb64
-rw-r--r--spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb62
2 files changed, 126 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb
new file mode 100644
index 0000000..85536d3
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb
@@ -0,0 +1,64 @@
+#! /usr/bin/env/ruby -S rspec
+
+require "spec_helper"
+
+describe Puppet::Parser::Functions.function(:validate_ipv4_address) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe "when calling validate_ipv4_address from puppet" do
+ describe "when given IPv4 address strings" do
+ it "should compile with one argument" do
+ Puppet[:code] = "validate_ipv4_address('1.2.3.4')"
+ scope.compiler.compile
+ end
+
+ it "should compile with multiple arguments" do
+ Puppet[:code] = "validate_ipv4_address('1.2.3.4', '5.6.7.8')"
+ scope.compiler.compile
+ end
+ end
+
+ describe "when given an IPv6 address" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv4_address('3ffe:505')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/)
+ end
+ end
+
+ describe "when given other strings" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv4_address('hello', 'world')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/)
+ end
+ end
+
+ describe "when given numbers" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv4_address(1, 2)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /is not a valid IPv4 address/)
+ end
+ end
+
+ describe "when given booleans" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv4_address(true, false)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /is not a string/)
+ end
+ end
+
+ it "should not compile when no arguments are passed" do
+ Puppet[:code] = "validate_ipv4_address()"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb
new file mode 100644
index 0000000..bf3c966
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb
@@ -0,0 +1,62 @@
+#! /usr/bin/env/ruby -S rspec
+
+require "spec_helper"
+
+describe Puppet::Parser::Functions.function(:validate_ipv6_address) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe "when calling validate_ipv6_address from puppet" do
+ describe "when given IPv6 address strings" do
+ it "should compile with one argument" do
+ Puppet[:code] = "validate_ipv6_address('3ffe:505:2')"
+ scope.compiler.compile
+ end
+
+ it "should compile with multiple arguments" do
+ Puppet[:code] = "validate_ipv6_address('3ffe:505:2', '3ffe:505:1')"
+ scope.compiler.compile
+ end
+ end
+
+ describe "when given an ipv4 address" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv6_address('1.2.3.4')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/)
+ end
+ end
+
+ describe "when given other strings" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv6_address('hello', 'world')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/)
+ end
+ end
+
+ describe "when given numbers" do
+ it "should compile" do
+ Puppet[:code] = "validate_ipv6_address(1, 2)"
+ scope.compiler.compile
+ end
+ end
+
+ describe "when given booleans" do
+ it "should not compile" do
+ Puppet[:code] = "validate_ipv6_address(true, false)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /is not a string/)
+ end
+ end
+
+ it "should not compile when no arguments are passed" do
+ Puppet[:code] = "validate_ipv6_address()"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+ end
+end