X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fensure_resource_spec.rb;h=9bbfaccf8fec4777bf9feb7e8adfa90c99533275;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=c847bf76b6fe51d80b3bdef1988d7309803fa40b;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/ensure_resource_spec.rb b/3rdparty/modules/stdlib/spec/functions/ensure_resource_spec.rb old mode 100755 new mode 100644 index c847bf76b..9bbfaccf8 --- a/3rdparty/modules/stdlib/spec/functions/ensure_resource_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/ensure_resource_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe 'ensure_resource' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) } - it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) } + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a type}) } + it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, %r{Must specify a title}) } if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) } else @@ -11,125 +11,139 @@ describe 'ensure_resource' do end it { - pending("should not accept numbers as arguments") - is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError) + pending('should not accept numbers as arguments') + is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError) } - context 'given an empty catalog' do + context 'when given an empty catalog' do describe 'after running ensure_resource("user", "username1", {})' do - before { subject.call(['User', 'username1', {}]) } + before(:each) { subject.execute('User', 'username1', {}) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').without_ensure } + it { expect(-> { catalogue }).to contain_user('username1').without_ensure } end describe 'after running ensure_resource("user", "username1", { gid => undef })' do - before { subject.call(['User', 'username1', { 'gid' => :undef }]) } + before(:each) { subject.execute('User', 'username1', 'gid' => undef_value) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').without_ensure } - it { expect(lambda { catalogue }).to contain_user('username1').without_gid } + it { expect(-> { catalogue }).to contain_user('username1').without_ensure } + it { expect(-> { catalogue }).to contain_user('username1').without_gid } end describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do - before { subject.call(['User', 'username1', { 'ensure' => 'present', 'gid' => :undef }]) } + before(:each) { subject.execute('User', 'username1', 'ensure' => 'present', 'gid' => undef_value) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } - it { expect(lambda { catalogue }).to contain_user('username1').without_gid } + it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('username1').without_gid } end describe 'after running ensure_resource("test::deftype", "foo", {})' do - before { subject.call(['test::deftype', 'foo', {}]) } + let(:pre_condition) { 'define test::deftype { }' } + + before(:each) { subject.execute('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 } + it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure } end end - context 'given a catalog with UTF8 chars' do + context 'when given a catalog with UTF8 chars' do describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do - before { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) } + before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', {}) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } + it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } end describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do - before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) } + before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', 'gid' => undef_value) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } - it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } + it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } + it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } end describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do - before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) } + before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', 'ensure' => 'present', 'gid' => undef_value) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') } - it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } + it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } end end - context 'given a catalog with "user { username1: ensure => present }"' do + context 'when given a catalog with "user { username1: ensure => present }"' do let(:pre_condition) { 'user { username1: ensure => present }' } describe 'after running ensure_resource("user", "username1", {})' do - before { subject.call(['User', 'username1', {}]) } + before(:each) { subject.execute('User', 'username1', {}) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') } end describe 'after running ensure_resource("user", "username2", {})' do - before { subject.call(['User', 'username2', {}]) } + before(:each) { subject.execute('User', 'username2', {}) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } - it { expect(lambda { catalogue }).to contain_user('username2').without_ensure } + it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('username2').without_ensure } end describe 'after running ensure_resource("user", "username1", { gid => undef })' do - before { subject.call(['User', 'username1', { 'gid' => :undef }]) } + before(:each) { subject.execute('User', 'username1', 'gid' => undef_value) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') } end describe 'after running ensure_resource("user", ["username1", "username2"], {})' do - before { subject.call(['User', ['username1', 'username2'], {}]) } + before(:each) { subject.execute('User', ['username1', 'username2'], {}) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } - it { expect(lambda { catalogue }).to contain_user('username2').without_ensure } + it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(-> { catalogue }).to contain_user('username2').without_ensure } end describe 'when providing already set params' do let(:params) { { 'ensure' => 'present' } } - before { subject.call(['User', ['username2', 'username3'], params]) } + + before(:each) { subject.execute('User', ['username2', 'username3'], params) } # this lambda is required due to strangeness within rspec-puppet's expectation handling - it { expect(lambda { catalogue }).to contain_user('username1').with(params) } - it { expect(lambda { catalogue }).to contain_user('username2').with(params) } + it { expect(-> { catalogue }).to contain_user('username1').with(params) } + it { expect(-> { catalogue }).to contain_user('username2').with(params) } end context 'when trying to add params' do - it { is_expected.to run \ - .with_params('User', 'username1', { 'ensure' => 'present', 'shell' => true }) \ - .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, /User\[username1\] is already declared/) + it { + is_expected.to run \ + .with_params('User', 'username1', 'ensure' => 'present', 'shell' => true) \ + .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, %r{User\[username1\] is already declared}) } end end - context 'given a catalog with "test::deftype { foo: }"' do - let(:pre_condition) { 'test::deftype { "foo": }' } + context 'when given a catalog with "test::deftype { foo: }"' do + let(:pre_condition) { 'define test::deftype { } test::deftype { "foo": }' } describe 'after running ensure_resource("test::deftype", "foo", {})' do - before { subject.call(['test::deftype', 'foo', {}]) } + before(:each) { subject.execute('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 } + it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure } + end + end + + if Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 + def undef_value + :undef + end + else + def undef_value + nil end end end