Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: add some more nginx.conf tests #628

Merged
merged 1 commit into from
May 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 158 additions & 1 deletion spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@

describe "nginx.conf template content" do
[
{
:title => 'should not set user',
:attr => 'super_user',
:value => false,
:notmatch => /user/,
},
{
:title => 'should set user',
:attr => 'daemon_user',
:value => 'test-user',
:match => 'user test-user;',
},
{
:title => 'should set worker_processes',
:attr => 'worker_processes',
Expand All @@ -94,6 +106,18 @@
:value => '/path/to/error.log',
:match => 'error_log /path/to/error.log;',
},
{
:title => 'should set pid',
:attr => 'pid',
:value => '/path/to/pid',
:match => 'pid /path/to/pid;',
},
{
:title => 'should not set pid',
:attr => 'pid',
:value => false,
:notmatch => /pid/,
},
{
:title => 'should set worker_connections',
:attr => 'worker_connections',
Expand All @@ -118,18 +142,108 @@
:value => {},
:notmatch => /log_format/,
},
{
:title => 'should set multi_accept',
:attr => 'multi_accept',
:value => 'on',
:match => /\s*multi_accept\s+on;/,
},
{
:title => 'should not set multi_accept',
:attr => 'multi_accept',
:value => 'off',
:notmatch => /multi_accept/,
},
{
:title => 'should set events_use',
:attr => 'events_use',
:value => 'eventport',
:match => /\s*use\s+eventport;/,
},
{
:title => 'should not set events_use',
:attr => 'events_use',
:value => false,
:notmatch => /use /,
},
{
:title => 'should set access_log',
:attr => 'http_access_log',
:value => '/path/to/access.log',
:match => ' access_log /path/to/access.log;',
},
{
:title => 'should set sendfile',
:attr => 'sendfile',
:value => 'on',
:match => ' sendfile on;',
},
{
:title => 'should not set sendfile',
:attr => 'sendfile',
:value => false,
:notmatch => /sendfile/,
},
{
:title => 'should set server_tokens',
:attr => 'server_tokens',
:value => 'on',
:match => ' server_tokens on;',
},
{
:title => 'should set types_hash_max_size',
:attr => 'types_hash_max_size',
:value => 10,
:match => ' types_hash_max_size 10;',
},
{
:title => 'should set types_hash_bucket_size',
:attr => 'types_hash_bucket_size',
:value => 10,
:match => ' types_hash_bucket_size 10;',
},
{
:title => 'should set server_names_hash_bucket_size',
:attr => 'names_hash_bucket_size',
:value => 10,
:match => ' server_names_hash_bucket_size 10;',
},
{
:title => 'should set server_names_hash_max_size',
:attr => 'names_hash_max_size',
:value => 10,
:match => ' server_names_hash_max_size 10;',
},
{
:title => 'should set keepalive_timeout',
:attr => 'keepalive_timeout',
:value => '123',
:match => ' keepalive_timeout 123;',
},
{
:title => 'should set tcp_nodelay',
:attr => 'http_tcp_nodelay',
:value => 'on',
:match => ' tcp_nodelay on;',
},
{
:title => 'should set tcp_nopush',
:attr => 'http_tcp_nopush',
:value => 'on',
:match => ' tcp_nopush on;',
},
{
:title => 'should set gzip',
:attr => 'gzip',
:value => 'on',
:match => ' gzip on;',
},
{
:title => 'should not set gzip',
:attr => 'gzip',
:value => 'off',
:notmatch => /gzip/,
},
{
:title => 'should set proxy_cache_path',
:attr => 'proxy_cache_path',
Expand All @@ -140,7 +254,31 @@
:title => 'should not set proxy_cache_path',
:attr => 'proxy_cache_path',
:value => false,
:notmatch => %r'\s+proxy_cache_path\s+/path/to/proxy\.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;',
:notmatch => /proxy_cache_path/,
},
{
:title => 'should set fastcgi_cache_path',
:attr => 'fastcgi_cache_path',
:value => '/path/to/proxy.cache',
:match => %r'\s*fastcgi_cache_path\s+/path/to/proxy.cache levels=1 keys_zone=d3:100m max_size=500m inactive=20m;',
},
{
:title => 'should not set fastcgi_cache_path',
:attr => 'fastcgi_cache_path',
:value => false,
:notmatch => /fastcgi_cache_path/,
},
{
:title => 'should set fastcgi_cache_use_stale',
:attr => 'fastcgi_cache_use_stale',
:value => 'invalid_header',
:match => ' fastcgi_cache_use_stale invalid_header;',
},
{
:title => 'should not set fastcgi_cache_use_stale',
:attr => 'fastcgi_cache_use_stale',
:value => false,
:notmatch => /fastcgi_cache_use_stale/,
},
{
:title => 'should contain ordered appended directives from hash',
Expand Down Expand Up @@ -223,6 +361,18 @@
:value => '123',
:match => ' keepalive_timeout 123;',
},
{
:title => 'should set mail',
:attr => 'mail',
:value => true,
:match => 'mail {',
},
{
:title => 'should not set mail',
:attr => 'mail',
:value => false,
:notmatch => /mail/,
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end
Expand Down Expand Up @@ -316,6 +466,13 @@
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;}) }
it { is_expected.to contain_file('/path/to/nginx/nginx.conf').with_content(%r{include /path/to/nginx/conf\.d/\*\.conf;}) }
it { is_expected.to contain_file('/path/to/nginx/nginx.conf').with_content(%r{include /path/to/nginx/sites-enabled/\*;}) }
end

context "when confd_purge true" do
let(:params) {{:confd_purge => true}}
it { is_expected.to contain_file('/etc/nginx/conf.d').with(
Expand Down