Adjusted tests for proxy variables.

This commit is contained in:
John Daniels 2015-06-15 08:44:16 -04:00
parent 10f7710e8d
commit 310ed828c2

View file

@ -48,12 +48,6 @@ describe 'nginx::config' do
:group => 'root',
:mode => '0644'
)}
it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with(
:ensure => 'file',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { is_expected.to contain_file("/tmp/nginx.d").with(
:ensure => 'absent',
:purge => true,
@ -379,6 +373,51 @@ describe 'nginx::config' do
:value => false,
:notmatch => /mail/,
},
{
:title => 'should set proxy_buffers',
:attr => 'proxy_buffers',
:value => '50 5k',
:match => ' proxy_buffers 50 5k;',
},
{
:title => 'should set proxy_buffer_size',
:attr => 'proxy_buffer_size',
:value => '2k',
:match => ' proxy_buffer_size 2k;',
},
{
:title => 'should set proxy_http_version',
:attr => 'proxy_http_version',
:value => '1.1',
:match => ' proxy_http_version 1.1;',
},
{
:title => 'should not set proxy_http_version',
:attr => 'proxy_http_version',
:value => nil,
:notmatch => 'proxy_http_version',
},
{
:title => 'should contain ordered appended directives',
:attr => 'proxy_set_header',
:value => ['header1','header2'],
:match => [
' proxy_set_header header1;',
' proxy_set_header header2;',
],
},
{
:title => 'should set client_body_temp_path',
:attr => 'client_body_temp_path',
:value => '/path/to/body_temp',
:match => ' client_body_temp_path /path/to/body_temp;',
},
{
:title => 'should set proxy_temp_path',
:attr => 'proxy_temp_path',
:value => '/path/to/proxy_temp',
:match => ' proxy_temp_path /path/to/proxy_temp;',
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end
@ -402,76 +441,6 @@ describe 'nginx::config' do
end
end
describe "proxy.conf template content" do
[
{
:title => 'should set proxy_buffers',
:attr => 'proxy_buffers',
:value => '50 5k',
:match => 'proxy_buffers 50 5k;',
},
{
:title => 'should set proxy_buffer_size',
:attr => 'proxy_buffer_size',
:value => '2k',
:match => 'proxy_buffer_size 2k;',
},
{
:title => 'should set proxy_http_version',
:attr => 'proxy_http_version',
:value => '1.1',
:match => 'proxy_http_version 1.1;',
},
{
:title => 'should not set proxy_http_version',
:attr => 'proxy_http_version',
:value => nil,
:notmatch => 'proxy_http_version',
},
{
:title => 'should contain ordered appended directives',
:attr => 'proxy_set_header',
:value => ['header1','header2'],
:match => [
'proxy_set_header header1;',
'proxy_set_header header2;',
],
},
{
:title => 'should set client_body_temp_path',
:attr => 'client_body_temp_path',
:value => '/path/to/body_temp',
:match => 'client_body_temp_path /path/to/body_temp;',
},
{
:title => 'should set proxy_temp_path',
:attr => 'proxy_temp_path',
:value => '/path/to/proxy_temp',
:match => 'proxy_temp_path /path/to/proxy_temp;',
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end
it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_file('/etc/nginx/conf.d/proxy.conf').with_content(item) }
else
lines = catalogue.resource('file', '/etc/nginx/conf.d/proxy.conf').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_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
end
end
end
end
end
context "when conf_dir is /path/to/nginx" do
let(:params) {{:conf_dir => '/path/to/nginx'}}
it { is_expected.to contain_file('/path/to/nginx/nginx.conf').with_content(%r{include /path/to/nginx/mime\.types;}) }