diff --git a/manifests/server/options.pp b/manifests/server/options.pp index 77dd6ed5..0074f8d8 100644 --- a/manifests/server/options.pp +++ b/manifests/server/options.pp @@ -15,18 +15,24 @@ # 'forwarders' => [ '8.8.8.8', '8.8.4.4' ], # } # -define dns::server::options inherits dns::server::params ( +define dns::server::options( $forwarders = [], ) { + if ! defined(Class['::dns::server']) { + fail('You must include the ::dns::server base class before using any dns options defined resources') + } + + validate_array($forwarders) + file { $title: ensure => present, - owner => $owner, - group => $group, + owner => $::dns::server::params::owner, + group => $::dns::server::params::group, mode => '0644', - require => [File[${cfg_dir}], Class['dns::server::install']], - content => template("${module_name}/named.conf.options.erb"), - notify => Class['dns::server::service'], + require => [File[$::dns::server::params::cfg_dir], Class['::dns::server::install']], + content => template("${module_name}/named.conf.options.erb"), + notify => Class['::dns::server::service'], } } diff --git a/spec/defines/dns__acl_spec.rb b/spec/defines/dns__acl_spec.rb index 139ad2ee..b9b2f720 100644 --- a/spec/defines/dns__acl_spec.rb +++ b/spec/defines/dns__acl_spec.rb @@ -3,8 +3,9 @@ describe 'dns::acl' do let(:title) { 'trusted' } + let(:facts) { { :concat_basedir => '/tmp' } } + context 'passing a string to data' do - let :facts do { :concat_basedir => '/dne', } end let :params do { :data => '192.168.0.0/24' } end @@ -15,7 +16,6 @@ end context 'passing an array to data' do - let :facts do { :concat_basedir => '/dne', } end let :params do { :data => [ '192.168.0.0/24' ] } end diff --git a/spec/defines/dns_server_options_spec.rb b/spec/defines/dns_server_options_spec.rb new file mode 100644 index 00000000..4cf57eb0 --- /dev/null +++ b/spec/defines/dns_server_options_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'dns::server::options', :type => :define do + let :pre_condition do + 'class { "::dns::server": }' + end + + let(:facts) { { :osfamily => 'Debian', :concat_basedir => '/tmp' } } + + let(:title) { '/etc/bind/named.conf.options' } + + context 'passing valid array to forwarders' do + let :params do + { :forwarders => [ '8.8.8.8', '4.4.4.4' ] } + end + + it { should contain_file('/etc/bind/named.conf.options') } + it { should contain_file('/etc/bind/named.conf.options').with_content(/8\.8\.8\.8;$/) } + it { should contain_file('/etc/bind/named.conf.options').with_content(/4\.4\.4\.4;$/) } + it { should contain_file('/etc/bind/named.conf.options').with_ensure("present") } + it { should contain_file('/etc/bind/named.conf.options').with_owner("bind") } + it { should contain_file('/etc/bind/named.conf.options').with_group("bind") } + + end + + context 'passing a string to forwarders' do + let :params do + { :forwarders => '8.8.8.8' } + end + + it 'should fail input validation' do + expect { subject }.to raise_error(Puppet::Error, /is not an Array/) + end + end + +end +