summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHailee Kenney <hailee@puppetlabs.com>2016-12-02 14:21:45 +0000
committerHailee Kenney <hailee@puppetlabs.com>2016-12-08 18:16:17 +0000
commit903d94e10527df8a288138d223e07f816422fa2c (patch)
treede9aac5352d4c4bee7668c73cb6ff297582dad48 /spec
parent85bdbcf79232f89203b65b9fa1a2e7bc7ddc067a (diff)
(MODULES-3829) Add tests for ensure_resources
Prior to this commit, we didn't have tests for the ensure_resources function (only for the ensure_resource function). This meant that we weren't catching a bug in the ensure_resources function. In order to prevent this in the future, add some tests which test the specific functionality of ensure_resources.
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/test/manifests/ensure_resources.pp4
-rw-r--r--spec/unit/ensure_resources_spec.rb22
2 files changed, 26 insertions, 0 deletions
diff --git a/spec/fixtures/test/manifests/ensure_resources.pp b/spec/fixtures/test/manifests/ensure_resources.pp
new file mode 100644
index 0000000..bd26002
--- /dev/null
+++ b/spec/fixtures/test/manifests/ensure_resources.pp
@@ -0,0 +1,4 @@
+# A helper class to test the ensure_resources function
+class test::ensure_resources($resource_type, $title_hash, $attributes_hash) {
+ ensure_resources($resource_type, $title_hash, $attributes_hash)
+}
diff --git a/spec/unit/ensure_resources_spec.rb b/spec/unit/ensure_resources_spec.rb
new file mode 100644
index 0000000..aea723e
--- /dev/null
+++ b/spec/unit/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