From d664a38cfb81b9aaa6f356bd31a9022b78de17af Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Mon, 21 Apr 2014 23:42:44 -0600 Subject: [PATCH 1/6] Spec file names should use double underscores for the delimeter in place of double colons --- .../{dns_server_config_spec.rb => dns__server__config_spec.rb} | 0 .../{dns_server_install_spec.rb => dns__server__install_spec.rb} | 0 .../{dns_server_options_spec.rb => dns__server__options_spec.rb} | 0 spec/defines/{dns_zone_spec.rb => dns__zone_spec.rb} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename spec/classes/{dns_server_config_spec.rb => dns__server__config_spec.rb} (100%) rename spec/classes/{dns_server_install_spec.rb => dns__server__install_spec.rb} (100%) rename spec/defines/{dns_server_options_spec.rb => dns__server__options_spec.rb} (100%) rename spec/defines/{dns_zone_spec.rb => dns__zone_spec.rb} (100%) diff --git a/spec/classes/dns_server_config_spec.rb b/spec/classes/dns__server__config_spec.rb similarity index 100% rename from spec/classes/dns_server_config_spec.rb rename to spec/classes/dns__server__config_spec.rb diff --git a/spec/classes/dns_server_install_spec.rb b/spec/classes/dns__server__install_spec.rb similarity index 100% rename from spec/classes/dns_server_install_spec.rb rename to spec/classes/dns__server__install_spec.rb diff --git a/spec/defines/dns_server_options_spec.rb b/spec/defines/dns__server__options_spec.rb similarity index 100% rename from spec/defines/dns_server_options_spec.rb rename to spec/defines/dns__server__options_spec.rb diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns__zone_spec.rb similarity index 100% rename from spec/defines/dns_zone_spec.rb rename to spec/defines/dns__zone_spec.rb From 3566d8aba59fe3947c89fd2e58ccb822a9c3cde8 Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Tue, 22 Apr 2014 21:20:40 -0600 Subject: [PATCH 2/6] Refactoring tests and switching to rspec-puppet trunk --- Gemfile | 2 +- Gemfile.lock | 11 ++++++++--- spec/classes/dns__server__config_spec.rb | 7 ++++--- spec/classes/dns__server__install_spec.rb | 5 +++-- spec/defines/dns__acl_spec.rb | 9 ++------- spec/defines/dns__server__options_spec.rb | 5 ++--- spec/defines/dns__zone_spec.rb | 10 +++------- 7 files changed, 23 insertions(+), 26 deletions(-) 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/dns__server__config_spec.rb b/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 index 99cc4794..de622055 100644 --- a/spec/classes/dns__server__install_spec.rb +++ b/spec/classes/dns__server__install_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'dns::server::install', :type => :class do - context "on an unknown OS" do - it { expect { subject }.to raise_error() } + context "on an unsupported OS" do + it{ should raise_error(/dns::server is incompatible with this osfamily/) } end context "on a Debian OS" do @@ -12,6 +12,7 @@ :operatingsystemrelease => '6', } end + it { should contain_class('dns::server::params') } it { should contain_package("bind9") } 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 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 index d1579d35..d464a8dd 100644 --- a/spec/defines/dns__zone_spec.rb +++ b/spec/defines/dns__zone_spec.rb @@ -9,9 +9,7 @@ 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 + it { should raise_error(Puppet::Error, /is not an Array/) } end context 'passing an array to data' do @@ -22,9 +20,7 @@ } 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.test.com.include'). @@ -56,7 +52,7 @@ with_content(/2001:db8::\/32/) } - it { + it { should contain_concat('/etc/bind/zones/db.test.com.stage') } From 0916cdf61c2efb8a2443d88751d8bad9558eeb35 Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Tue, 22 Apr 2014 21:20:59 -0600 Subject: [PATCH 3/6] Adding coverage helper --- spec/classes/coverage_spec.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 spec/classes/coverage_spec.rb 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! } From 62df6993c0b5c9e97334628b199c4d62e495ad15 Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Tue, 22 Apr 2014 21:21:10 -0600 Subject: [PATCH 4/6] New tests --- spec/classes/dns__server__service_spec.rb | 17 +++++++++++++++++ spec/classes/dns__server_spec.rb | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 spec/classes/dns__server__service_spec.rb create mode 100644 spec/classes/dns__server_spec.rb 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 From f3ce1ef855f4d93ca8c389404747ca1fe2887ad4 Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Tue, 22 Apr 2014 21:59:56 -0600 Subject: [PATCH 5/6] Refactor zone spec. Much more to do as this is a very complex defined type --- spec/defines/dns__zone_spec.rb | 162 ++++++++++++++++----------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/spec/defines/dns__zone_spec.rb b/spec/defines/dns__zone_spec.rb index d464a8dd..64bb4c01 100644 --- a/spec/defines/dns__zone_spec.rb +++ b/spec/defines/dns__zone_spec.rb @@ -2,95 +2,93 @@ 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 + context 'on a supported operating system' do + let(:facts) {{ :osfamily => 'Debian', :concat_basedir => '/mock_dir' }} - it { should raise_error(Puppet::Error, /is not an Array/) } - end + 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 - 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_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 + 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 - 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;/) + 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 - 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 + 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 From 3bc09b443de36af295bd5ccb15616909c6096a42 Mon Sep 17 00:00:00 2001 From: David Danzilio Date: Tue, 22 Apr 2014 22:01:15 -0600 Subject: [PATCH 6/6] refactoring dns::server::install spec --- spec/classes/dns__server__install_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/classes/dns__server__install_spec.rb b/spec/classes/dns__server__install_spec.rb index de622055..ef80afa1 100644 --- a/spec/classes/dns__server__install_spec.rb +++ b/spec/classes/dns__server__install_spec.rb @@ -6,14 +6,11 @@ end context "on a Debian OS" do - let :facts do - { - :osfamily => 'Debian', - :operatingsystemrelease => '6', - } - end + let(:facts) {{ :osfamily => 'Debian' }} it { should contain_class('dns::server::params') } - it { should contain_package("bind9") } + ['bind9', 'dnssec-tools'].each do |package| + it { should contain_package(package) } + end end end