diff options
author | David Schmitt <david.schmitt@puppet.com> | 2016-12-09 14:55:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-09 14:55:59 +0000 |
commit | f63644a0385f5f27f4285b91ea6e367a515fdfc2 (patch) | |
tree | 6a50cd6fe21c0d14e315ae6b2c713327ccf60b17 /spec | |
parent | 7507af555361b2dcba8ed6189dc54c21e64ea031 (diff) | |
parent | 3312cc1f44d1acf25ce45701a74cecd647c50858 (diff) |
Merge pull request #697 from HAIL9000/issue/master/MODULES-3829_add_tests_for_ensure_resources
(MODULES-3829) Add tests for ensure_resources
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/test/manifests/ensure_resources.pp | 4 | ||||
-rwxr-xr-x | spec/functions/ensure_packages_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/ensure_resources_spec.rb | 22 |
3 files changed, 34 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/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index c824732..5d97684 100755 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -33,4 +33,12 @@ describe 'ensure_packages' do it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present').with_provider("gem") } end end + + context 'given hash of packages' do + before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) } + it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) } + end end 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 |