shared_examples.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. shared_examples_for "a Puppet::Error" do |description|
  2. it "with message matching #{description.inspect}" do
  3. expect { is_expected.to have_class_count(1) }.to raise_error(Puppet::Error, description)
  4. end
  5. end
  6. shared_examples 'generic nova service' do |service|
  7. context 'with default parameters' do
  8. it 'installs package and service' do
  9. is_expected.to contain_package(service[:name]).with({
  10. :name => service[:package_name],
  11. :ensure => 'present',
  12. :tag => ['openstack', 'nova-package'],
  13. })
  14. is_expected.to contain_package(service[:name]).that_requires('Anchor[nova::install::begin]')
  15. is_expected.to contain_package(service[:name]).that_notifies('Anchor[nova::install::end]')
  16. is_expected.to contain_service(service[:name]).with({
  17. :name => service[:service_name],
  18. :ensure => 'running',
  19. :hasstatus => true,
  20. :enable => true,
  21. :tag => 'nova-service',
  22. })
  23. is_expected.to contain_service(service[:name]).that_subscribes_to('Anchor[nova::service::begin]')
  24. is_expected.to contain_service(service[:name]).that_notifies('Anchor[nova::service::end]')
  25. end
  26. end
  27. context 'with overridden parameters' do
  28. let :params do
  29. { :enabled => false,
  30. :ensure_package => '2012.1-2' }
  31. end
  32. it 'installs package and service' do
  33. is_expected.to contain_package(service[:name]).with({
  34. :name => service[:package_name],
  35. :ensure => '2012.1-2',
  36. :tag => ['openstack', 'nova-package'],
  37. })
  38. is_expected.to contain_package(service[:name]).that_requires('Anchor[nova::install::begin]')
  39. is_expected.to contain_package(service[:name]).that_notifies('Anchor[nova::install::end]')
  40. is_expected.to contain_service(service[:name]).with({
  41. :name => service[:service_name],
  42. :ensure => 'stopped',
  43. :hasstatus => true,
  44. :enable => false,
  45. :tag => 'nova-service',
  46. })
  47. is_expected.to contain_service(service[:name]).that_subscribes_to('Anchor[nova::service::begin]')
  48. is_expected.to contain_service(service[:name]).that_notifies('Anchor[nova::service::end]')
  49. end
  50. end
  51. context 'while not managing service state' do
  52. let :params do
  53. { :enabled => false,
  54. :manage_service => false }
  55. end
  56. it 'does not control service state' do
  57. is_expected.to contain_service(service[:name]).without_ensure
  58. end
  59. end
  60. end