2014-06-12 20:12:24 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'nginx::resource::map' do
|
|
|
|
let :title do
|
|
|
|
'backend_pool'
|
|
|
|
end
|
|
|
|
|
|
|
|
let :default_params do
|
|
|
|
{
|
|
|
|
:string => '$uri',
|
|
|
|
:default => 'pool_a',
|
|
|
|
:mappings => {
|
|
|
|
'foo' => 'pool_b',
|
|
|
|
'bar' => 'pool_c',
|
|
|
|
'baz' => 'pool_d',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-06-13 16:05:30 +02:00
|
|
|
let :pre_condition do
|
|
|
|
[
|
2014-06-16 16:55:37 +02:00
|
|
|
'include ::nginx::config',
|
2014-06-13 16:05:30 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2014-06-12 20:12:24 +02:00
|
|
|
describe 'os-independent items' do
|
|
|
|
describe 'basic assumptions' do
|
|
|
|
let :params do default_params end
|
|
|
|
|
2014-07-18 04:28:38 +02:00
|
|
|
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with(
|
2014-06-12 20:12:24 +02:00
|
|
|
{
|
|
|
|
'owner' => 'root',
|
|
|
|
'group' => 'root',
|
|
|
|
'mode' => '0644',
|
|
|
|
'ensure' => 'file',
|
|
|
|
'content' => /map \$uri \$#{title}/,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "map.conf template content" do
|
|
|
|
[
|
|
|
|
{
|
|
|
|
:title => 'should set hostnames',
|
|
|
|
:attr => 'hostnames',
|
|
|
|
:value => true,
|
|
|
|
:match => ' hostnames;'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:title => 'should set default',
|
|
|
|
:attr => 'default',
|
|
|
|
:value => 'pool_a',
|
|
|
|
:match => [ ' default pool_a;' ],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:title => 'should contain ordered mappings',
|
|
|
|
:attr => 'mappings',
|
|
|
|
:value => {
|
|
|
|
'foo' => 'pool_b',
|
|
|
|
'bar' => 'pool_c',
|
|
|
|
'baz' => 'pool_d',
|
|
|
|
},
|
|
|
|
:match => [
|
|
|
|
' bar pool_c;',
|
|
|
|
' baz pool_d;',
|
|
|
|
' foo pool_b;',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
].each do |param|
|
|
|
|
context "when #{param[:attr]} is #{param[:value]}" do
|
|
|
|
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
|
|
|
|
2014-07-18 04:28:38 +02:00
|
|
|
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') }
|
2014-06-12 20:12:24 +02:00
|
|
|
it param[:title] do
|
2014-12-03 05:07:20 +01:00
|
|
|
verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-map.conf", Array(param[:match]))
|
2014-06-12 20:12:24 +02:00
|
|
|
Array(param[:notmatch]).each do |item|
|
2014-07-18 04:28:38 +02:00
|
|
|
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").without_content(item)
|
2014-06-12 20:12:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ensure => absent' do
|
|
|
|
let :params do default_params.merge(
|
|
|
|
{
|
|
|
|
:ensure => 'absent'
|
|
|
|
}
|
|
|
|
) end
|
|
|
|
|
2014-07-18 04:28:38 +02:00
|
|
|
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
|
2014-06-12 20:12:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|