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 refactor #49

Merged
merged 6 commits into from
Apr 23, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ group :test do
gem "rake"
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0'
gem "puppet-lint"
gem "rspec-puppet", '~> 1.0.0'
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
gem "puppet-syntax"
gem "puppetlabs_spec_helper"
end
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/rodjek/rspec-puppet.git
revision: 03e94422fb9bbdd950d5a0bec6ead5d76e06616b
specs:
rspec-puppet (1.0.1)
rspec

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -32,8 +39,6 @@ GEM
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-puppet (1.0.1)
rspec

PLATFORMS
ruby
Expand All @@ -44,4 +49,4 @@ DEPENDENCIES
puppet-syntax
puppetlabs_spec_helper
rake
rspec-puppet (~> 1.0.0)
rspec-puppet!
1 change: 1 addition & 0 deletions spec/classes/coverage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
at_exit { RSpec::Puppet::Coverage.report! }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. We are really stepping it up :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in love with the coverage feature!

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

describe 'dns::server::config', :type => :class do

context "on an unknown OS" do
let :facts do { :concat_basedir => '/dne', } end
it { expect { subject }.to raise_error() }
context "on an unsupported OS" do
let :facts do { :osfamily => 'Solaris', :concat_basedir => '/dne', } end
it { should raise_error(/dns::server is incompatible with this osfamily/) }
end

context "on a Debian OS" do
Expand All @@ -15,6 +15,7 @@
:concat_basedir => '/dne',
}
end

it { should contain_file('/etc/bind/').with_owner('bind') }
end

Expand Down
17 changes: 17 additions & 0 deletions spec/classes/dns__server__install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe 'dns::server::install', :type => :class do
context "on an unsupported OS" do
it{ should raise_error(/dns::server is incompatible with this osfamily/) }
end

context "on a Debian OS" do
let(:facts) {{ :osfamily => 'Debian' }}
it { should contain_class('dns::server::params') }
['bind9', 'dnssec-tools'].each do |package|
it { should contain_package(package) }
end
end

end

17 changes: 17 additions & 0 deletions spec/classes/dns__server__service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe 'dns::server::service' do
let(:facts) {{ :concat_basedir => '/mock_dir' }}
context 'on a supported OS' do
let(:facts) {{ :osfamily => 'Debian' }}

it { should contain_service('bind9').with_require('Class[Dns::Server::Config]') }
end

context 'on an unsupported OS' do
let(:facts) {{ :osfamily => 'Solaris' }}

it { should raise_error(/dns::server is incompatible with this osfamily: Solaris/) }
end

end
9 changes: 9 additions & 0 deletions spec/classes/dns__server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'dns::server' do
let(:facts) {{ :osfamily => 'Debian', :concat_basedir => '/dne' }}

it { should contain_class('dns::server::install') }
it { should contain_class('dns::server::config') }
it { should contain_class('dns::server::service') }
end
19 changes: 0 additions & 19 deletions spec/classes/dns_server_install_spec.rb

This file was deleted.

9 changes: 2 additions & 7 deletions spec/defines/dns__acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

describe 'dns::acl' do
let(:title) { 'trusted' }

let(:facts) { { :concat_basedir => '/tmp' } }

context 'passing a string to data' do
let :params do
{ :data => '192.168.0.0/24' }
end

it 'should fail input validation' do
expect { subject }.to raise_error(Puppet::Error, /is not an Array/)
end
it { should raise_error(Puppet::Error, /is not an Array/) }
end

context 'passing an array to data' do
let :params do
{ :data => [ '192.168.0.0/24' ] }
end

it 'should pass input validation' do
expect { subject }.to_not raise_error
end
it { should_not raise_error }

it {
should contain_concat__fragment('named.conf.local.acl.trusted.include').
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
{ :forwarders => '8.8.8.8' }
end

it 'should fail input validation' do
expect { subject }.to raise_error(Puppet::Error, /is not an Array/)
end
it { should raise_error(Puppet::Error, /is not an Array/) }

end

end
Expand Down
94 changes: 94 additions & 0 deletions spec/defines/dns__zone_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require 'spec_helper'

describe 'dns::zone' do
let(:pre_condition) { 'include dns::server::params' }
let(:title) { 'test.com' }

context 'on a supported operating system' do
let(:facts) {{ :osfamily => 'Debian', :concat_basedir => '/mock_dir' }}

describe 'passing something other than an array to $allow_transfer' do
let(:params) {{ :allow_transfer => '127.0.0.1' }}
it { should raise_error(Puppet::Error, /is not an Array/) }
end

describe 'passing something other than an array to $allow_forwarder' do
let(:params) {{ :allow_forwarder => '127.0.0.1' }}
it { should raise_error(Puppet::Error, /is not an Array/) }
end

describe 'passing an array to $allow_transfer and $allow_forwarder' do
let(:params) do {
:allow_transfer => ['192.0.2.0', '2001:db8::/32'],
:allow_forwarder => ['8.8.8.8', '208.67.222.222']
}
end

it { should_not raise_error }

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/allow-transfer/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/192\.0\.2\.0/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forwarders/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward first;/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/8.8.8.8/)
}

it {
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/2001:db8::\/32/)
}

it { should contain_concat('/etc/bind/zones/db.test.com.stage') }

it { should contain_concat__fragment('db.test.com.soa').
with_content(/_SERIAL_/)
}

it { should contain_exec('bump-test.com-serial').
with_refreshonly('true')
}
end

context 'when ask to have a only forward policy' do
let :params do
{ :allow_transfer => [],
:allow_forwarder => ['8.8.8.8', '208.67.222.222'],
:forward_policy => 'only'
}
end

it 'should have a forward only policy' do
should contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward only;/)
end
end

context 'with no explicit forward policy or forwarder' do
let(:params) {{ :allow_transfer => ['192.0.2.0', '2001:db8::/32'] }}

it 'should not have any forwarder configuration' do
should_not contain_concat__fragment('named.conf.local.test.com.include').
with_content(/forward/)
end
end
end
end

100 changes: 0 additions & 100 deletions spec/defines/dns_zone_spec.rb

This file was deleted.