Added spec tests and set proxy to undef for streamhost
This commit is contained in:
parent
7df1b40475
commit
45c6162bf1
2 changed files with 139 additions and 2 deletions
|
@ -66,7 +66,7 @@ define nginx::resource::streamhost (
|
|||
$ipv6_listen_ip = '::',
|
||||
$ipv6_listen_port = '80',
|
||||
$ipv6_listen_options = 'default ipv6only=on',
|
||||
$proxy,
|
||||
$proxy = undef,
|
||||
$proxy_read_timeout = $::nginx::config::proxy_read_timeout,
|
||||
$proxy_connect_timeout = $::nginx::config::proxy_connect_timeout,
|
||||
$resolver = [],
|
||||
|
@ -99,7 +99,6 @@ define nginx::resource::streamhost (
|
|||
validate_string($ipv6_listen_options)
|
||||
|
||||
validate_string($proxy_read_timeout)
|
||||
validate_string($proxy_redirect)
|
||||
|
||||
validate_array($resolver)
|
||||
validate_array($server_name)
|
||||
|
|
138
spec/defines/resource_stream_spec.rb
Normal file
138
spec/defines/resource_stream_spec.rb
Normal file
|
@ -0,0 +1,138 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::resource::streamhost' do
|
||||
let :title do
|
||||
'www.rspec.example.com'
|
||||
end
|
||||
let :default_params do
|
||||
{
|
||||
:ipv6_enable => true,
|
||||
}
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:ipaddress6 => '::',
|
||||
}
|
||||
end
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
]
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do default_params end
|
||||
it { is_expected.to contain_class("nginx::config") }
|
||||
it { is_expected.to contain_concat("/etc/nginx/streams-available/#{title}.conf").with({
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})}
|
||||
it { is_expected.to contain_file("#{title}.conf symlink").with({
|
||||
'ensure' => 'link',
|
||||
'path' => "/etc/nginx/streams-enabled/#{title}.conf",
|
||||
'target' => "/etc/nginx/streams-available/#{title}.conf"
|
||||
})}
|
||||
end
|
||||
|
||||
describe "vhost_header template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the IPv4 listen IP',
|
||||
:attr => 'listen_ip',
|
||||
:value => '127.0.0.1',
|
||||
:match => %r'\s+listen\s+127.0.0.1:80;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen port',
|
||||
:attr => 'listen_port',
|
||||
:value => 45,
|
||||
:match => %r'\s+listen\s+\*:45;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen options',
|
||||
:attr => 'listen_options',
|
||||
:value => 'spdy default',
|
||||
:match => %r'\s+listen\s+\*:80 spdy default;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => true,
|
||||
:match => %r'\s+listen\s+\[::\]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => false,
|
||||
:notmatch => %r'\slisten \[::\]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen IP',
|
||||
:attr => 'ipv6_listen_ip',
|
||||
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
:match => %r'\s+listen\s+\[2001:0db8:85a3:0000:0000:8a2e:0370:7334\]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => 45,
|
||||
:match => %r'\s+listen\s+\[::\]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => 'spdy',
|
||||
:match => %r'\s+listen\s+\[::\]:80 spdy;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
:value => ['www.foo.com','foo.com'],
|
||||
:match => %r'\s+server_name\s+www.foo.com foo.com;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain raw_prepend directives',
|
||||
:attr => 'raw_prepend',
|
||||
:value => [
|
||||
'if (a) {',
|
||||
' b;',
|
||||
'}'
|
||||
],
|
||||
:match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
|
||||
},
|
||||
{
|
||||
:title => 'should contain raw_append directives',
|
||||
:attr => 'raw_append',
|
||||
:value => [
|
||||
'if (a) {',
|
||||
' b;',
|
||||
'}'
|
||||
],
|
||||
:match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { is_expected.to contain_concat__fragment("#{title}-header") }
|
||||
it param[:title] do
|
||||
matches = Array(param[:match])
|
||||
|
||||
if matches.all? { |m| m.is_a? Regexp }
|
||||
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-header").with_content(item) }
|
||||
else
|
||||
lines = catalogue.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
|
||||
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
|
||||
end
|
||||
Array(param[:notmatch]).each do |item|
|
||||
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue