ensure_resource_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /usr/bin/env ruby -S rspec
  2. require 'spec_helper'
  3. require 'rspec-puppet'
  4. describe 'ensure_resource' do
  5. describe 'when a type or title is not specified' do
  6. it { should run.with_params().and_raise_error(ArgumentError) }
  7. it { should run.with_params(['type']).and_raise_error(ArgumentError) }
  8. end
  9. describe 'when compared against a resource with no attributes' do
  10. let :pre_condition do
  11. 'user { "dan": }'
  12. end
  13. it "should contain the the ensured resources" do
  14. subject.should run.with_params('user', 'dan', {})
  15. compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
  16. end
  17. end
  18. describe 'when compared against a resource with attributes' do
  19. let :pre_condition do
  20. 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
  21. end
  22. # these first three should not fail
  23. it { should run.with_params('User', 'dan', {}) }
  24. it { should run.with_params('User', 'dan', '') }
  25. it { should run.with_params('User', 'dan', {'ensure' => 'present'}) }
  26. it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) }
  27. # test that this fails
  28. it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) }
  29. end
  30. describe 'when an array of new resources are passed in' do
  31. it "should contain the ensured resources" do
  32. subject.should run.with_params('User', ['dan', 'alex'], {})
  33. compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
  34. compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
  35. end
  36. end
  37. describe 'when an array of existing resources is compared against existing resources' do
  38. let :pre_condition do
  39. 'user { "dan": ensure => present; "alex": ensure => present }'
  40. end
  41. it "should return the existing resources" do
  42. subject.should run.with_params('User', ['dan', 'alex'], {})
  43. compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
  44. compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
  45. end
  46. end
  47. describe 'when compared against existing resources with attributes' do
  48. let :pre_condition do
  49. 'user { "dan": ensure => present; "alex": ensure => present }'
  50. end
  51. # These should not fail
  52. it { should run.with_params('User', ['dan', 'alex'], {}) }
  53. it { should run.with_params('User', ['dan', 'alex'], '') }
  54. it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) }
  55. # This should fail
  56. it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) }
  57. end
  58. end