From 296aab51eb4925dcc80cb60bd2d99f51d121df99 Mon Sep 17 00:00:00 2001 From: Steven Post Date: Mon, 16 Mar 2015 13:29:38 +0100 Subject: [PATCH] The base class must be defined first so the parameters are known This also implies the dependency for the tests needed to be changed. Because of the changed dependency, tests needed some extra facts to please the concat module. --- manifests/dev.pp | 3 --- manifests/package.pp | 6 ++++++ spec/classes/dev_spec.rb | 29 +++++++++++++++++++++++------ spec/classes/mod/dev_spec.rb | 20 +++++++++++--------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/manifests/dev.pp b/manifests/dev.pp index 6bd865606..b1947e934 100644 --- a/manifests/dev.pp +++ b/manifests/dev.pp @@ -1,7 +1,4 @@ class apache::dev { - if $::osfamily == 'FreeBSD' and !defined(Class['apache::package']) { - fail('apache::dev requires apache::package; please include apache or apache::package class first') - } include ::apache::params $packages = $::apache::params::dev_packages if $packages { # FreeBSD doesn't have dev packages to install diff --git a/manifests/package.pp b/manifests/package.pp index 6595cb92d..728b26010 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -2,6 +2,12 @@ $ensure = 'present', $mpm_module = $::apache::params::mpm_module, ) inherits ::apache::params { + + # The base class must be included first because it is used by parameter defaults + if ! defined(Class['apache']) { + fail('You must include the apache base class before using any apache defined resources') + } + case $::osfamily { 'FreeBSD': { case $mpm_module { diff --git a/spec/classes/dev_spec.rb b/spec/classes/dev_spec.rb index e2e0b47af..eb3d76593 100644 --- a/spec/classes/dev_spec.rb +++ b/spec/classes/dev_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' describe 'apache::dev', :type => :class do + let(:pre_condition) {[ + 'include apache' + ]} context "on a Debian OS" do let :facts do { @@ -9,6 +12,10 @@ :operatingsystem => 'Debian', :operatingsystemrelease => '6', :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => 'Linux' } end it { is_expected.to contain_class("apache::params") } @@ -25,6 +32,10 @@ :operatingsystem => 'Ubuntu', :operatingsystemrelease => '14.04', :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => 'Linux' } end it { is_expected.to contain_package("apache2-dev") } @@ -36,29 +47,31 @@ :operatingsystem => 'RedHat', :operatingsystemrelease => '6', :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => 'Linux' } end it { is_expected.to contain_class("apache::params") } it { is_expected.to contain_package("httpd-devel") } end context "on a FreeBSD OS" do - let :pre_condition do - 'include apache::package' - end let :facts do { :osfamily => 'FreeBSD', :operatingsystem => 'FreeBSD', :operatingsystemrelease => '9', :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => 'FreeBSD' } end it { is_expected.to contain_class("apache::params") } end context "on a Gentoo OS" do - let :pre_condition do - 'include apache::package' - end let :facts do { :osfamily => 'Gentoo', @@ -66,6 +79,10 @@ :operatingsystemrelease => '3.16.1-gentoo', :concat_basedir => '/dne', :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => 'Linux' } end it { is_expected.to contain_class("apache::params") } diff --git a/spec/classes/mod/dev_spec.rb b/spec/classes/mod/dev_spec.rb index f65338977..1686a0275 100644 --- a/spec/classes/mod/dev_spec.rb +++ b/spec/classes/mod/dev_spec.rb @@ -1,16 +1,14 @@ require 'spec_helper' describe 'apache::mod::dev', :type => :class do + let(:pre_condition) {[ + 'include apache' + ]} [ - ['RedHat', '6', 'Santiago'], - ['Debian', '6', 'squeeze'], - ['FreeBSD', '9', 'FreeBSD'], - ].each do |osfamily, operatingsystemrelease, lsbdistcodename| - if osfamily == 'FreeBSD' - let :pre_condition do - 'include apache::package' - end - end + ['RedHat', '6', 'Santiago', 'Linux'], + ['Debian', '6', 'squeeze', 'Linux'], + ['FreeBSD', '9', 'FreeBSD', 'FreeBSD'], + ].each do |osfamily, operatingsystemrelease, lsbdistcodename, kernel| context "on a #{osfamily} OS" do let :facts do { @@ -19,6 +17,10 @@ :operatingsystem => osfamily, :operatingsystemrelease => operatingsystemrelease, :is_pe => false, + :concat_basedir => '/foo', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + :kernel => kernel } end it { is_expected.to contain_class('apache::dev') }