resource_stream_spec.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. require 'spec_helper'
  2. describe 'nginx::resource::streamhost' do
  3. let :title do
  4. 'www.rspec.example.com'
  5. end
  6. let :default_params do
  7. {
  8. :ipv6_enable => true,
  9. }
  10. end
  11. let :facts do
  12. {
  13. :ipaddress6 => '::',
  14. }
  15. end
  16. let :pre_condition do
  17. [
  18. 'include ::nginx::config',
  19. ]
  20. end
  21. describe 'os-independent items' do
  22. describe 'basic assumptions' do
  23. let :params do default_params end
  24. it { is_expected.to contain_class("nginx::config") }
  25. it { is_expected.to contain_concat("/etc/nginx/streams-available/#{title}.conf").with({
  26. 'owner' => 'root',
  27. 'group' => 'root',
  28. 'mode' => '0644',
  29. })}
  30. it { is_expected.to contain_file("#{title}.conf symlink").with({
  31. 'ensure' => 'link',
  32. 'path' => "/etc/nginx/streams-enabled/#{title}.conf",
  33. 'target' => "/etc/nginx/streams-available/#{title}.conf"
  34. })}
  35. end
  36. describe "vhost_header template content" do
  37. [
  38. {
  39. :title => 'should set the IPv4 listen IP',
  40. :attr => 'listen_ip',
  41. :value => '127.0.0.1',
  42. :match => %r'\s+listen\s+127.0.0.1:80;',
  43. },
  44. {
  45. :title => 'should set the IPv4 listen port',
  46. :attr => 'listen_port',
  47. :value => 45,
  48. :match => %r'\s+listen\s+\*:45;',
  49. },
  50. {
  51. :title => 'should set the IPv4 listen options',
  52. :attr => 'listen_options',
  53. :value => 'spdy default',
  54. :match => %r'\s+listen\s+\*:80 spdy default;',
  55. },
  56. {
  57. :title => 'should enable IPv6',
  58. :attr => 'ipv6_enable',
  59. :value => true,
  60. :match => %r'\s+listen\s+\[::\]:80 default ipv6only=on;',
  61. },
  62. {
  63. :title => 'should not enable IPv6',
  64. :attr => 'ipv6_enable',
  65. :value => false,
  66. :notmatch => %r'\slisten \[::\]:80 default ipv6only=on;',
  67. },
  68. {
  69. :title => 'should set the IPv6 listen IP',
  70. :attr => 'ipv6_listen_ip',
  71. :value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  72. :match => %r'\s+listen\s+\[2001:0db8:85a3:0000:0000:8a2e:0370:7334\]:80 default ipv6only=on;',
  73. },
  74. {
  75. :title => 'should set the IPv6 listen port',
  76. :attr => 'ipv6_listen_port',
  77. :value => 45,
  78. :match => %r'\s+listen\s+\[::\]:45 default ipv6only=on;',
  79. },
  80. {
  81. :title => 'should set the IPv6 listen options',
  82. :attr => 'ipv6_listen_options',
  83. :value => 'spdy',
  84. :match => %r'\s+listen\s+\[::\]:80 spdy;',
  85. },
  86. {
  87. :title => 'should set servername(s)',
  88. :attr => 'server_name',
  89. :value => ['www.foo.com','foo.com'],
  90. :match => %r'\s+server_name\s+www.foo.com foo.com;',
  91. },
  92. {
  93. :title => 'should contain raw_prepend directives',
  94. :attr => 'raw_prepend',
  95. :value => [
  96. 'if (a) {',
  97. ' b;',
  98. '}'
  99. ],
  100. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  101. },
  102. {
  103. :title => 'should contain raw_append directives',
  104. :attr => 'raw_append',
  105. :value => [
  106. 'if (a) {',
  107. ' b;',
  108. '}'
  109. ],
  110. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  111. },
  112. ].each do |param|
  113. context "when #{param[:attr]} is #{param[:value]}" do
  114. let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
  115. it { is_expected.to contain_concat__fragment("#{title}-header") }
  116. it param[:title] do
  117. matches = Array(param[:match])
  118. if matches.all? { |m| m.is_a? Regexp }
  119. matches.each { |item| is_expected.to contain_concat__fragment("#{title}-header").with_content(item) }
  120. else
  121. lines = catalogue.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
  122. expect(lines & Array(param[:match])).to eq(Array(param[:match]))
  123. end
  124. Array(param[:notmatch]).each do |item|
  125. is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
  126. end
  127. end
  128. end
  129. end
  130. end
  131. end
  132. end