diff --git a/Gemfile b/Gemfile index aa968f5c..fe677c23 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index ff2c8506..7203a3fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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: @@ -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 @@ -44,4 +49,4 @@ DEPENDENCIES puppet-syntax puppetlabs_spec_helper rake - rspec-puppet (~> 1.0.0) + rspec-puppet! diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb new file mode 100644 index 00000000..12513b83 --- /dev/null +++ b/spec/classes/coverage_spec.rb @@ -0,0 +1 @@ +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/classes/dns_server_config_spec.rb b/spec/classes/dns__server__config_spec.rb similarity index 64% rename from spec/classes/dns_server_config_spec.rb rename to spec/classes/dns__server__config_spec.rb index f0bb3d4c..aecbf74c 100644 --- a/spec/classes/dns_server_config_spec.rb +++ b/spec/classes/dns__server__config_spec.rb @@ -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 @@ -15,6 +15,7 @@ :concat_basedir => '/dne', } end + it { should contain_file('/etc/bind/').with_owner('bind') } end diff --git a/spec/classes/dns__server__install_spec.rb b/spec/classes/dns__server__install_spec.rb new file mode 100644 index 00000000..ef80afa1 --- /dev/null +++ b/spec/classes/dns__server__install_spec.rb @@ -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 + diff --git a/spec/classes/dns__server__service_spec.rb b/spec/classes/dns__server__service_spec.rb new file mode 100644 index 00000000..e0fd5d57 --- /dev/null +++ b/spec/classes/dns__server__service_spec.rb @@ -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 diff --git a/spec/classes/dns__server_spec.rb b/spec/classes/dns__server_spec.rb new file mode 100644 index 00000000..d7722a68 --- /dev/null +++ b/spec/classes/dns__server_spec.rb @@ -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 diff --git a/spec/classes/dns_server_install_spec.rb b/spec/classes/dns_server_install_spec.rb deleted file mode 100644 index 99cc4794..00000000 --- a/spec/classes/dns_server_install_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe 'dns::server::install', :type => :class do - context "on an unknown OS" do - it { expect { subject }.to raise_error() } - end - - context "on a Debian OS" do - let :facts do - { - :osfamily => 'Debian', - :operatingsystemrelease => '6', - } - end - it { should contain_package("bind9") } - end - -end - diff --git a/spec/defines/dns__acl_spec.rb b/spec/defines/dns__acl_spec.rb index b9b2f720..20f7ad9d 100644 --- a/spec/defines/dns__acl_spec.rb +++ b/spec/defines/dns__acl_spec.rb @@ -2,7 +2,6 @@ describe 'dns::acl' do let(:title) { 'trusted' } - let(:facts) { { :concat_basedir => '/tmp' } } context 'passing a string to data' do @@ -10,9 +9,7 @@ { :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 @@ -20,9 +17,7 @@ { :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'). diff --git a/spec/defines/dns_server_options_spec.rb b/spec/defines/dns__server__options_spec.rb similarity index 89% rename from spec/defines/dns_server_options_spec.rb rename to spec/defines/dns__server__options_spec.rb index 4cf57eb0..7ad78e35 100644 --- a/spec/defines/dns_server_options_spec.rb +++ b/spec/defines/dns__server__options_spec.rb @@ -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 diff --git a/spec/defines/dns__zone_spec.rb b/spec/defines/dns__zone_spec.rb new file mode 100644 index 00000000..64bb4c01 --- /dev/null +++ b/spec/defines/dns__zone_spec.rb @@ -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 + diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb deleted file mode 100644 index d1579d35..00000000 --- a/spec/defines/dns_zone_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -require 'spec_helper' - -describe 'dns::zone' do - let(:pre_condition) { 'include dns::server::params' } - - let(:title) { 'test.com' } - - context 'passing something other than an array' do - let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end - let :params do { :allow_transfer => '127.0.0.1' } end - - it 'should fail input validation' do - expect { subject }.to raise_error(Puppet::Error, /is not an Array/) - end - end - - context 'passing an array to data' do - let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end - 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 pass input validation' do - expect { subject }.to_not raise_error - end - - 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 :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end - 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 'In the default case with no explicit forward policy or forwarder' do - let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } end - let :params do - { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], - } - end - - 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 -