resource_map_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 :facts do
  18. {
  19. :osfamily => 'RedHat',
  20. :operatingsystem => 'CentOS',
  21. }
  22. end
  23. let :pre_condition do
  24. [
  25. 'include ::nginx::params',
  26. 'include ::nginx::config',
  27. ]
  28. end
  29. describe 'os-independent items' do
  30. describe 'basic assumptions' do
  31. let :params do default_params end
  32. it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with(
  33. {
  34. 'owner' => 'root',
  35. 'group' => 'root',
  36. 'mode' => '0644',
  37. 'ensure' => 'file',
  38. 'content' => /map \$uri \$#{title}/,
  39. }
  40. )}
  41. end
  42. describe "map.conf template content" do
  43. [
  44. {
  45. :title => 'should set hostnames',
  46. :attr => 'hostnames',
  47. :value => true,
  48. :match => ' hostnames;'
  49. },
  50. {
  51. :title => 'should set default',
  52. :attr => 'default',
  53. :value => 'pool_a',
  54. :match => [ ' default pool_a;' ],
  55. },
  56. {
  57. :title => 'should contain ordered mappings',
  58. :attr => 'mappings',
  59. :value => {
  60. 'foo' => 'pool_b',
  61. 'bar' => 'pool_c',
  62. 'baz' => 'pool_d',
  63. },
  64. :match => [
  65. ' bar pool_c;',
  66. ' baz pool_d;',
  67. ' foo pool_b;',
  68. ],
  69. },
  70. ].each do |param|
  71. context "when #{param[:attr]} is #{param[:value]}" do
  72. let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
  73. it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') }
  74. it param[:title] do
  75. verify_contents(subject, "/etc/nginx/conf.d/#{title}-map.conf", Array(param[:match]))
  76. Array(param[:notmatch]).each do |item|
  77. should contain_file("/etc/nginx/conf.d/#{title}-map.conf").without_content(item)
  78. end
  79. end
  80. end
  81. end
  82. context 'when ensure => absent' do
  83. let :params do default_params.merge(
  84. {
  85. :ensure => 'absent'
  86. }
  87. ) end
  88. it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
  89. end
  90. end
  91. end
  92. end