Skip to content

Commit

Permalink
Merge pull request voxpupuli#628 from 3flex/add-spec-test
Browse files Browse the repository at this point in the history
spec: add some more nginx.conf tests
  • Loading branch information
3flex committed May 8, 2015
2 parents 8df2b7f + c207528 commit 328fad1
Showing 1 changed file with 158 additions and 1 deletion.
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

0 comments on commit 328fad1

Please sign in to comment.