summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/aliases/absolute_path_spec.rb62
-rw-r--r--spec/aliases/array_spec.rb34
-rw-r--r--spec/aliases/bool_spec.rb32
-rw-r--r--spec/aliases/string_spec.rb31
-rw-r--r--spec/fixtures/modules/test/manifests/absolute_path.pp6
-rw-r--r--spec/fixtures/modules/test/manifests/array.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/bool.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/string.pp8
-rwxr-xr-xspec/functions/is_array_spec.rb5
-rwxr-xr-xspec/functions/is_bool_spec.rb5
-rwxr-xr-xspec/functions/is_string_spec.rb5
-rwxr-xr-xspec/functions/validate_absolute_path_spec.rb7
-rwxr-xr-xspec/functions/validate_array_spec.rb5
-rwxr-xr-xspec/functions/validate_bool_spec.rb7
-rwxr-xr-xspec/functions/validate_re_spec.rb6
-rwxr-xr-xspec/functions/validate_string_spec.rb6
16 files changed, 235 insertions, 0 deletions
diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb
new file mode 100644
index 0000000..0bcdf85
--- /dev/null
+++ b/spec/aliases/absolute_path_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::absolute_path', type: :class do
+ describe 'valid paths handling' do
+ %w{
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ //host/windows
+ /
+ /var/tmp
+ /var/opt/../lib/puppet
+ }.each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'invalid path handling' do
+ context 'garbage inputs' do
+ [
+ nil,
+ [ nil ],
+ [ nil, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ ].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::Absolute_path/) }
+ end
+ end
+ end
+
+ context 'relative paths' do
+ %w{
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ relative\\windows
+ }.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::Absolute_path/) }
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/array_spec.rb b/spec/aliases/array_spec.rb
new file mode 100644
index 0000000..8bbb8b3
--- /dev/null
+++ b/spec/aliases/array_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::array', type: :class do
+ describe 'accepts arrays' do
+ [
+ [],
+ ['one'],
+ [1],
+ [{}],
+ [[]],
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ '',
+ 'one',
+ '1',
+ {},
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::Array/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/bool_spec.rb b/spec/aliases/bool_spec.rb
new file mode 100644
index 0000000..f664457
--- /dev/null
+++ b/spec/aliases/bool_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::bool', type: :class do
+ describe 'accepts booleans' do
+ [
+ true,
+ false,
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ [1],
+ [{}],
+ [true],
+ 'true',
+ 'false',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::Bool/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb
new file mode 100644
index 0000000..8e01d55
--- /dev/null
+++ b/spec/aliases/string_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::string', type: :class do
+ describe 'accepts strings' do
+ [
+ '',
+ 'one',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ [],
+ {},
+ 1,
+ true,
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::String = String/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/modules/test/manifests/absolute_path.pp b/spec/fixtures/modules/test/manifests/absolute_path.pp
new file mode 100644
index 0000000..d77f6bd
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/absolute_path.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Absolute_path type alias
+class test::absolute_path(
+ Stdlib::Compat::Absolute_path $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/modules/test/manifests/array.pp b/spec/fixtures/modules/test/manifests/array.pp
new file mode 100644
index 0000000..84b6a5b
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/array.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Array type alias
+class test::array(
+ Stdlib::Compat::Array $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/modules/test/manifests/bool.pp b/spec/fixtures/modules/test/manifests/bool.pp
new file mode 100644
index 0000000..ab5b5ea
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/bool.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Bool type alias
+class test::bool(
+ Stdlib::Compat::Bool $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/modules/test/manifests/string.pp b/spec/fixtures/modules/test/manifests/string.pp
new file mode 100644
index 0000000..6508c70
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/string.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::String type alias
+class test::string(
+ Stdlib::Compat::String $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb
index 7dd21c2..e35ca44 100755
--- a/spec/functions/is_array_spec.rb
+++ b/spec/functions/is_array_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_array' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params([])
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it {
pending("Current implementation ignores parameters after the first.")
diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb
index 76d619b..9569856 100755
--- a/spec/functions/is_bool_spec.rb
+++ b/spec/functions/is_bool_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_bool' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(true)
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params(true).and_return(true) }
diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb
index 8e459cc..8056ed4 100755
--- a/spec/functions/is_string_spec.rb
+++ b/spec/functions/is_string_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_string' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('ha')
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it {
pending("Current implementation ignores parameters after the first.")
diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb
index 4a8404d..ffdb2c8 100755
--- a/spec/functions/validate_absolute_path_spec.rb
+++ b/spec/functions/validate_absolute_path_spec.rb
@@ -1,6 +1,13 @@
require 'spec_helper'
describe 'validate_absolute_path' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ # called twice because validate_absolute_path calls is_absolute_path
+ scope.expects(:warn).with(includes('This method is deprecated')).twice
+ is_expected.to run.with_params('c:/')
+ end
+
describe 'signature validation' 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) }
diff --git a/spec/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb
index 4ee7754..0ba7108 100755
--- a/spec/functions/validate_array_spec.rb
+++ b/spec/functions/validate_array_spec.rb
@@ -3,6 +3,11 @@ require 'spec_helper'
describe 'validate_array' do
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params([])
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
describe 'valid inputs' do
diff --git a/spec/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb
index d9cdf57..b0f41a8 100755
--- a/spec/functions/validate_bool_spec.rb
+++ b/spec/functions/validate_bool_spec.rb
@@ -1,6 +1,13 @@
require 'spec_helper'
describe 'validate_bool' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ #called twice, because validate_bool calls is_bool
+ scope.expects(:warn).with(includes('This method is deprecated')).twice
+ is_expected.to run.with_params(true)
+ end
+
describe 'signature validation' 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) }
diff --git a/spec/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb
index 3f90143..f6fa931 100755
--- a/spec/functions/validate_re_spec.rb
+++ b/spec/functions/validate_re_spec.rb
@@ -1,6 +1,12 @@
require 'spec_helper'
describe 'validate_re' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
describe 'signature validation' 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) }
diff --git a/spec/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb
index f0c500e..9bfef66 100755
--- a/spec/functions/validate_string_spec.rb
+++ b/spec/functions/validate_string_spec.rb
@@ -1,6 +1,12 @@
require 'spec_helper'
describe 'validate_string' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
describe 'signature validation' 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) }