Skip to content

Commit

Permalink
Merge pull request #1090 from alexjfisher/rspec-puppet-facts
Browse files Browse the repository at this point in the history
Use rspec-puppet-facts
  • Loading branch information
bastelfreak authored Jun 15, 2017
2 parents 3eb335c + 21bcf82 commit 37460c8
Show file tree
Hide file tree
Showing 11 changed files with 4,224 additions and 4,223 deletions.
6 changes: 3 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fixtures:
repositories:
apt: "git://github.com/puppetlabs/puppetlabs-apt.git"
concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
apt: "https://github.com/puppetlabs/puppetlabs-apt.git"
concat: "https://github.com/puppetlabs/puppetlabs-concat.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
nginx: "#{source_dir}"
2 changes: 1 addition & 1 deletion manifests/resource/mailhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
# and support does not exist for it in the kernel.
if ($ipv6_enable and !$::ipaddress6) {
if ($ipv6_enable and !$facts['ipaddress6']) {
warning('nginx: IPv6 support is not enabled or configured properly')
}

Expand Down
2,038 changes: 1,003 additions & 1,035 deletions spec/classes/nginx_spec.rb

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions spec/default_module_facts.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
---
osfamily: "Debian"
operatingsystem: "Debian"
operatingsystemmajrelease: "8"
lsbdistid: "Debian"
lsbdistcodename: "jessie"
ipaddress6: '::'
211 changes: 109 additions & 102 deletions spec/defines/resource_geo_spec.rb
Original file line number Diff line number Diff line change
@@ -1,121 +1,128 @@
require 'spec_helper'

describe 'nginx::resource::geo' do
let :title do
'client_network'
end

let :pre_condition do
[
'include ::nginx'
]
end

let :default_params do
{
default: 'extra',
networks: {
'172.16.0.0/12' => 'intra',
'192.168.0.0/16' => 'intra',
'10.0.0.0/8' => 'intra'
},
proxies: ['1.2.3.4', '4.3.2.1']
}
end

describe 'os-independent items' do
describe 'basic assumptions' do
let(:params) { default_params }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
let :title do
'client_network'
end

it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").that_requires('File[/etc/nginx/conf.d]') }
it do
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'ensure' => 'file',
'content' => %r{geo \$#{title}}
)
let :pre_condition do
[
'include ::nginx'
]
end
end

describe 'geo.conf template content' do
[
{
title: 'should set address',
attr: 'address',
value: '$remote_addr',
match: 'geo $remote_addr $client_network {'
},
{
title: 'should set ranges',
attr: 'ranges',
value: true,
match: ' ranges;'
},
{
title: 'should set default',
attr: 'default',
value: 'extra',
match: [' default extra;']
},
let :default_params do
{
title: 'should contain ordered network directives',
attr: 'networks',
value: {
'192.168.0.0/16' => 'intra',
default: 'extra',
networks: {
'172.16.0.0/12' => 'intra',
'192.168.0.0/16' => 'intra',
'10.0.0.0/8' => 'intra'
},
match: [
' 10.0.0.0/8 intra;',
' 172.16.0.0/12 intra;',
' 192.168.0.0/16 intra;'
]
},
{
title: 'should set multiple proxies',
attr: 'proxies',
value: ['1.2.3.4', '4.3.2.1'],
match: [
' proxy 1.2.3.4;',
' proxy 4.3.2.1;'
]
},
{
title: 'should set proxy_recursive',
attr: 'proxy_recursive',
value: true,
match: ' proxy_recursive;'
},
{
title: 'should set delete',
attr: 'delete',
value: '192.168.0.0/16',
match: ' delete 192.168.0.0/16;'
proxies: ['1.2.3.4', '4.3.2.1']
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }
end

it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_mode('0644') }
it param[:title] do
verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-geo.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").without_content(item)
end
describe 'os-independent items' do
describe 'basic assumptions' do
let(:params) { default_params }

it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").that_requires('File[/etc/nginx/conf.d]') }
it do
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'ensure' => 'file',
'content' => %r{geo \$#{title}}
)
end
end
end

context 'when ensure => absent' do
let :params do
default_params.merge(
ensure: 'absent'
)
end
describe 'geo.conf template content' do
[
{
title: 'should set address',
attr: 'address',
value: '$remote_addr',
match: 'geo $remote_addr $client_network {'
},
{
title: 'should set ranges',
attr: 'ranges',
value: true,
match: ' ranges;'
},
{
title: 'should set default',
attr: 'default',
value: 'extra',
match: [' default extra;']
},
{
title: 'should contain ordered network directives',
attr: 'networks',
value: {
'192.168.0.0/16' => 'intra',
'172.16.0.0/12' => 'intra',
'10.0.0.0/8' => 'intra'
},
match: [
' 10.0.0.0/8 intra;',
' 172.16.0.0/12 intra;',
' 192.168.0.0/16 intra;'
]
},
{
title: 'should set multiple proxies',
attr: 'proxies',
value: ['1.2.3.4', '4.3.2.1'],
match: [
' proxy 1.2.3.4;',
' proxy 4.3.2.1;'
]
},
{
title: 'should set proxy_recursive',
attr: 'proxy_recursive',
value: true,
match: ' proxy_recursive;'
},
{
title: 'should set delete',
attr: 'delete',
value: '192.168.0.0/16',
match: ' delete 192.168.0.0/16;'
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }

it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_mode('0644') }
it param[:title] do
verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-geo.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").without_content(item)
end
end
end
end

context 'when ensure => absent' do
let :params do
default_params.merge(
ensure: 'absent'
)
end

it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_ensure('absent') }
end
end
end
end
end
Expand Down
Loading

0 comments on commit 37460c8

Please sign in to comment.