resource_map_spec.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. require 'spec_helper'
  2. describe 'nginx::resource::map' do
  3. let :title do
  4. 'backend_pool'
  5. end
  6. let :default_params do
  7. {
  8. :string => '$uri',
  9. :default => 'pool_a',
  10. :mappings => {
  11. 'foo' => 'pool_b',
  12. 'bar' => 'pool_c',
  13. 'baz' => 'pool_d',
  14. },
  15. }
  16. end
  17. let :pre_condition do
  18. [
  19. 'include ::nginx::config',
  20. ]
  21. end
  22. describe 'os-independent items' do
  23. describe 'basic assumptions' do
  24. let :params do default_params end
  25. it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with(
  26. {
  27. 'owner' => 'root',
  28. 'group' => 'root',
  29. 'mode' => '0644',
  30. 'ensure' => 'file',
  31. 'content' => /map \$uri \$#{title}/,
  32. }
  33. )}
  34. end
  35. describe "map.conf template content" do
  36. [
  37. {
  38. :title => 'should set hostnames',
  39. :attr => 'hostnames',
  40. :value => true,
  41. :match => ' hostnames;'
  42. },
  43. {
  44. :title => 'should set default',
  45. :attr => 'default',
  46. :value => 'pool_a',
  47. :match => [ ' default pool_a;' ],
  48. },
  49. {
  50. :title => 'should contain ordered mappings',
  51. :attr => 'mappings',
  52. :value => {
  53. 'foo' => 'pool_b',
  54. 'bar' => 'pool_c',
  55. 'baz' => 'pool_d',
  56. },
  57. :match => [
  58. ' bar pool_c;',
  59. ' baz pool_d;',
  60. ' foo pool_b;',
  61. ],
  62. },
  63. ].each do |param|
  64. context "when #{param[:attr]} is #{param[:value]}" do
  65. let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
  66. it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') }
  67. it param[:title] do
  68. verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-map.conf", Array(param[:match]))
  69. Array(param[:notmatch]).each do |item|
  70. is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").without_content(item)
  71. end
  72. end
  73. end
  74. end
  75. context 'when ensure => absent' do
  76. let :params do default_params.merge(
  77. {
  78. :ensure => 'absent'
  79. }
  80. ) end
  81. it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
  82. end
  83. end
  84. end
  85. end