summaryrefslogtreecommitdiff
path: root/spec/functions
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functions')
-rwxr-xr-xspec/functions/defined_with_params_spec.rb28
-rwxr-xr-xspec/functions/ensure_packages_spec.rb8
-rwxr-xr-xspec/functions/ensure_resource_spec.rb18
-rw-r--r--spec/functions/ensure_resources_spec.rb22
4 files changed, 76 insertions, 0 deletions
diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb
index a0db0b7..491a03b 100755
--- a/spec/functions/defined_with_params_spec.rb
+++ b/spec/functions/defined_with_params_spec.rb
@@ -37,4 +37,32 @@ describe 'defined_with_params' do
it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) }
it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) }
end
+
+ describe 'when the reference is a' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ context 'reference' do
+ it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) }
+ end
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ context 'array' do
+ it 'fails' do
+ expect {
+ subject.call([['User[dan]'], {}])
+ }.to raise_error ArgumentError, /not understood: 'Array'/
+ end
+ end
+ end
+ end
+
+ describe 'when passed a defined type' do
+ let :pre_condition do
+ 'test::deftype { "foo": }'
+ end
+ it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
+ it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
+ end
end
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index 6f94d72..1f89785 100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -34,6 +34,14 @@ describe 'ensure_packages' do
end
end
+ context 'given an empty packages array' do
+ let(:pre_condition) { 'notify { "hi": } -> Package <| |>; $somearray = ["vim",""]; ensure_packages($somearray)' }
+
+ describe 'after running ensure_package(["vim", ""])' do
+ it { expect { catalogue }.to raise_error(Puppet::ParseError, /Empty String provided/) }
+ end
+ end
+
context 'given hash of packages' do
before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) }
before { subject.call([{"パッケージ" => { "ensure" => "absent"}}]) }
diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb
index 5366205..c847bf7 100755
--- a/spec/functions/ensure_resource_spec.rb
+++ b/spec/functions/ensure_resource_spec.rb
@@ -38,6 +38,13 @@ describe 'ensure_resource' do
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
end
+
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
end
context 'given a catalog with UTF8 chars' do
@@ -114,4 +121,15 @@ describe 'ensure_resource' do
}
end
end
+
+ context 'given a catalog with "test::deftype { foo: }"' do
+ let(:pre_condition) { 'test::deftype { "foo": }' }
+
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
+ end
end
diff --git a/spec/functions/ensure_resources_spec.rb b/spec/functions/ensure_resources_spec.rb
new file mode 100644
index 0000000..aea723e
--- /dev/null
+++ b/spec/functions/ensure_resources_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'test::ensure_resources', type: :class do
+ let(:params) {{ resource_type: 'user', title_hash: title_param, attributes_hash: {'ensure' => 'present'} }}
+
+ describe 'given a title hash of multiple resources' do
+
+ let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}} }
+
+ it { is_expected.to compile }
+ it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) }
+ it { is_expected.to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700', 'ensure' => 'present'}) }
+ end
+
+ describe 'given a title hash of a single resource' do
+
+ let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }} }
+
+ it { is_expected.to compile }
+ it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) }
+ end
+end