summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHelen Campbell <helen@puppetlabs.com>2016-08-16 11:55:05 +0100
committerHelen Campbell <helen@puppetlabs.com>2016-08-17 13:49:42 +0100
commit6d185bdaa19f698270a0df4b0a0c05618864b955 (patch)
tree2d005f4664838214a4e3284e73a2060453a1216c /spec
parent1d9d2c02d6669d4a6219140ae7ff3648a30c89cf (diff)
Deprecation of ip functions
Diffstat (limited to 'spec')
-rw-r--r--spec/aliases/ip_address.rb34
-rw-r--r--spec/aliases/ipv4_spec.rb32
-rw-r--r--spec/aliases/ipv6_spec.rb30
-rw-r--r--spec/fixtures/test/manifests/ip_address.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv4.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv6.pp6
-rwxr-xr-xspec/functions/is_ip_address_spec.rb5
-rw-r--r--spec/functions/is_ipv4_address_spec.rb17
-rw-r--r--spec/functions/is_ipv6_address_spec.rb17
-rw-r--r--spec/functions/validate_ip_address_spec.rb4
-rwxr-xr-xspec/functions/validate_ipv4_address_spec.rb5
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb4
12 files changed, 166 insertions, 0 deletions
diff --git a/spec/aliases/ip_address.rb b/spec/aliases/ip_address.rb
new file mode 100644
index 0000000..036bfe5
--- /dev/null
+++ b/spec/aliases/ip_address.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ip_address', type: :class do
+ describe 'accepts ipv4 and ipv6 addresses' do
+ [
+ '224.0.0.0',
+ '255.255.255.255',
+ '0.0.0.0',
+ '192.88.99.0',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2001:0db8:85a3:000000:0000:8a2e:0370:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb
new file mode 100644
index 0000000..640618c
--- /dev/null
+++ b/spec/aliases/ipv4_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ipv4', type: :class do
+ describe 'accepts ipv4 addresses' do
+ [
+ '224.0.0.0',
+ '255.255.255.255',
+ '0.0.0.0',
+ '192.88.99.0'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv4/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv6_spec.rb b/spec/aliases/ipv6_spec.rb
new file mode 100644
index 0000000..688eb16
--- /dev/null
+++ b/spec/aliases/ipv6_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ipv6', type: :class do
+ describe 'accepts ipv6 addresses' do
+ [
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2000:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv6/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/test/manifests/ip_address.pp b/spec/fixtures/test/manifests/ip_address.pp
new file mode 100644
index 0000000..bbbd804
--- /dev/null
+++ b/spec/fixtures/test/manifests/ip_address.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ip_address type alias
+class test::ip_address(
+ Stdlib::Compat::Ip_address $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv4.pp b/spec/fixtures/test/manifests/ipv4.pp
new file mode 100644
index 0000000..2e8022d
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv4.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv4 type alias
+class test::ipv4(
+ Stdlib::Compat::Ipv4 $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv6.pp b/spec/fixtures/test/manifests/ipv6.pp
new file mode 100644
index 0000000..7912fd6
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv6.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv6 type alias
+class test::ipv6(
+ Stdlib::Compat::Ipv6 $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb
index a7a383a..9386ca9 100755
--- a/spec/functions/is_ip_address_spec.rb
+++ b/spec/functions/is_ip_address_spec.rb
@@ -20,4 +20,9 @@ describe 'is_ip_address' do
it { is_expected.to run.with_params(1).and_return(false) }
it { is_expected.to run.with_params({}).and_return(false) }
it { is_expected.to run.with_params([]).and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
end
diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb
new file mode 100644
index 0000000..2b9fc49
--- /dev/null
+++ b/spec/functions/is_ipv4_address_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'is_ipv4_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('1.2.3.4').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3.255').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
+end
diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb
new file mode 100644
index 0000000..e3e4734
--- /dev/null
+++ b/spec/functions/is_ipv6_address_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'is_ipv6_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) }
+ it { is_expected.to run.with_params('85a3:0000:0000:8a2e:0370:7334:100.100.100.100').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
+ end
+end
diff --git a/spec/functions/validate_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb
index b56ce51..10f6c37 100644
--- a/spec/functions/validate_ip_address_spec.rb
+++ b/spec/functions/validate_ip_address_spec.rb
@@ -19,6 +19,10 @@ describe 'validate_ip_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
context 'with netmasks' do
it { is_expected.to run.with_params('8.8.8.8/0') }
it { is_expected.to run.with_params('8.8.8.8/16') }
diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb
index b6170d4..b67bf6f 100755
--- a/spec/functions/validate_ipv4_address_spec.rb
+++ b/spec/functions/validate_ipv4_address_spec.rb
@@ -5,6 +5,11 @@ describe 'validate_ipv4_address' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
+
describe 'valid inputs' do
it { is_expected.to run.with_params('0.0.0.0') }
it { is_expected.to run.with_params('8.8.8.8') }
diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 7aaf006..3afab56 100755
--- a/spec/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -10,6 +10,10 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('3ffe:0505:0002::')
+ end
end
describe 'invalid inputs' do