2013-11-22 04:10:53 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'nginx::resource::upstream' do
|
|
|
|
let :title do
|
|
|
|
'upstream-test'
|
|
|
|
end
|
|
|
|
|
|
|
|
let :default_params do
|
|
|
|
{
|
|
|
|
:members => ['test'],
|
|
|
|
}
|
|
|
|
end
|
2014-06-20 17:17:23 +02:00
|
|
|
|
2014-06-13 14:09:37 +02:00
|
|
|
let :pre_condition do
|
|
|
|
[
|
|
|
|
'include ::nginx::config',
|
|
|
|
]
|
|
|
|
end
|
2013-11-22 04:10:53 +01:00
|
|
|
|
2014-06-20 17:17:23 +02:00
|
|
|
let :pre_condition do
|
|
|
|
[
|
|
|
|
'include ::nginx::config',
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2013-11-22 04:10:53 +01: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_class('concat::setup') }
|
|
|
|
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-upstream.conf") }
|
|
|
|
it { is_expected.to contain_concat__fragment("#{title}_upstream_header").with_content(/upstream #{title}/) }
|
2014-06-20 17:17:23 +02:00
|
|
|
|
|
|
|
it {
|
2014-07-18 04:28:38 +02:00
|
|
|
is_expected.to contain_concat__fragment("#{title}_upstream_header").with(
|
2013-11-22 04:10:53 +01:00
|
|
|
{
|
2014-06-20 17:17:23 +02:00
|
|
|
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
|
|
|
|
'order' => 10,
|
2013-11-22 04:10:53 +01:00
|
|
|
}
|
|
|
|
)}
|
2014-06-20 17:17:23 +02:00
|
|
|
|
|
|
|
it {
|
2014-07-18 04:28:38 +02:00
|
|
|
is_expected.to contain_concat__fragment("#{title}_upstream_members").with(
|
2014-06-20 17:17:23 +02:00
|
|
|
{
|
|
|
|
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
|
|
|
|
'order' => 50,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
|
|
|
|
it {
|
2014-07-18 04:28:38 +02:00
|
|
|
is_expected.to contain_concat__fragment("#{title}_upstream_footer").with(
|
2014-06-20 17:17:23 +02:00
|
|
|
{
|
|
|
|
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
|
|
|
|
'order' => 90,
|
|
|
|
}).with_content("}\n")
|
|
|
|
}
|
2013-11-22 04:10:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "upstream.conf template content" do
|
|
|
|
[
|
|
|
|
{
|
2014-06-20 17:17:23 +02:00
|
|
|
:title => 'should contain ordered prepended directives',
|
|
|
|
:attr => 'upstream_cfg_prepend',
|
|
|
|
:fragment => 'header',
|
2013-11-22 04:10:53 +01:00
|
|
|
:value => {
|
|
|
|
'test3' => 'test value 3',
|
2014-06-20 17:17:23 +02:00
|
|
|
'test6' => {'subkey1' => ['subvalue1', 'subvalue2']},
|
2013-11-22 04:10:53 +01:00
|
|
|
'test1' => 'test value 1',
|
|
|
|
'test2' => 'test value 2',
|
2014-03-12 09:06:47 +01:00
|
|
|
'test5' => {'subkey1' => 'subvalue1'},
|
2014-06-20 17:17:23 +02:00
|
|
|
'test4' => ['test value 1', 'test value 2'],
|
2013-11-22 04:10:53 +01:00
|
|
|
},
|
|
|
|
:match => [
|
|
|
|
' test1 test value 1;',
|
|
|
|
' test2 test value 2;',
|
2013-11-22 05:04:39 +01:00
|
|
|
' test3 test value 3;',
|
2014-03-12 09:06:47 +01:00
|
|
|
' test4 test value 1;',
|
|
|
|
' test4 test value 2;',
|
|
|
|
' test5 subkey1 subvalue1;',
|
|
|
|
' test6 subkey1 subvalue1;',
|
|
|
|
' test6 subkey1 subvalue2;',
|
2013-11-22 04:10:53 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2014-06-20 17:17:23 +02:00
|
|
|
:title => 'should set server',
|
|
|
|
:attr => 'members',
|
|
|
|
:fragment => 'members',
|
|
|
|
:value => %W( test3 test1 test2 ),
|
|
|
|
:match => [
|
2014-02-03 14:36:06 +01:00
|
|
|
' server test3 fail_timeout=10s;',
|
|
|
|
' server test1 fail_timeout=10s;',
|
|
|
|
' server test2 fail_timeout=10s;',
|
2013-11-22 04:10:53 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
].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}-upstream.conf").with_mode('0644') }
|
|
|
|
it { is_expected.to contain_concat__fragment("#{title}_upstream_#{param[:fragment]}") }
|
2013-11-22 04:10:53 +01:00
|
|
|
it param[:title] do
|
2014-12-03 05:07:20 +01:00
|
|
|
lines = catalogue.resource('concat::fragment', "#{title}_upstream_#{param[:fragment]}").send(:parameters)[:content].split("\n")
|
2014-07-18 04:28:38 +02:00
|
|
|
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
|
2013-12-06 17:36:28 +01:00
|
|
|
Array(param[:notmatch]).each do |item|
|
2014-07-18 04:28:38 +02:00
|
|
|
is_expected.to contain_concat__fragment("#{title}_upstream_#{param[:fragment]}").without_content(item)
|
2013-12-06 17:36:28 +01:00
|
|
|
end
|
2013-11-22 04:10:53 +01:00
|
|
|
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}-upstream.conf").with_ensure('absent') }
|
2013-11-22 04:10:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|