diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 4c3f5e6..9fea763 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper_puppet' describe 'jboss', :type => :class do + extend Testing::JBoss::SharedExamples + extend Testing::RspecPuppet::Package let(:facts) do { :operatingsystem => 'OracleLinux', @@ -10,55 +12,60 @@ :puppetversion => Puppet.version } end + context 'with defaults for all parameters' do it { is_expected.to compile } - it do - is_expected.to contain_class('jboss').with({ - :product => 'wildfly', - :version => '8.2.0.Final', - :download_url => 'http://download.jboss.org/wildfly/8.2.0.Final/wildfly-8.2.0.Final.zip' - }) + it { is_expected.to contain_class('jboss::internal::package') } + it_behaves_like_full_working_jboss_installation + end + + context 'with product => jboss-wildfly parameters set' do + let(:product) { 'wildfly' } + let(:version) { '8.2.0.Final' } + let(:pre_condition) do + "class { 'jboss': product => '#{product}', version => '#{version}' }" end - it { is_expected.to contain_anchor 'jboss::begin' } - it { is_expected.to contain_anchor 'jboss::end' } - it { is_expected.to contain_anchor 'jboss::configuration::begin' } - it { is_expected.to contain_anchor 'jboss::configuration::end' } - it { is_expected.to contain_anchor 'jboss::installed' } - it { is_expected.to contain_anchor 'jboss::package::begin' } - it { is_expected.to contain_anchor 'jboss::package::end' } - it { is_expected.to contain_anchor 'jboss::service::begin' } - it { is_expected.to contain_anchor 'jboss::service::end' } - it { is_expected.to contain_anchor 'jboss::service::started' } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_class('jboss::internal::package').with({ - :version => '8.2.0.Final', - :product => 'wildfly', - :jboss_user => 'jboss', - :jboss_group => 'jboss', - :java_version => 'latest' - })} + it { is_expected.to compile } + package_files_for_jboss_product end + context 'with product => jboss-eap and version => 6.4.0.GA parameters set' do - let(:params) do - { :product => 'jboss-eap', :version => '6.4.0.GA' } + let(:product) { 'jboss-eap' } + let(:version) { '6.4.0.GA' } + let(:pre_condition) do + "class { 'jboss': product => '#{product}', version => '#{version}' }" + end + it { is_expected.to compile } + package_files_for_jboss_product({:product => 'jboss-eap', :version => '6.4.0.GA'}) + end + + context 'with product => jboss-eap and version => 6.2.0.GA parameters set' do + let(:product) { 'jboss-eap' } + let(:version) { '6.2.0.GA' } + let(:pre_condition) do + "class { 'jboss': product => '#{product}', version => '#{version}' }" end + it { is_expected.to compile } + package_files_for_jboss_product({:product => 'jboss-eap', :version => '6.2.0.GA'}) + end + context 'with product => jboss-as and version => 7.1.0.Final parameters set' do + let(:product) { 'jboss-as' } + let(:version) { '7.1.0.Final' } + let(:pre_condition) do + "class { 'jboss': product => '#{product}', version => '#{version}' }" + end it { is_expected.to compile } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_group 'jboss' } + package_files_for_jboss_product({:product => 'jboss-as', :version => '7.1.0.Final'}) end + context 'with jboss_user => appserver parameter set' do let(:params) do { :jboss_user => 'appserver' } end - it { is_expected.to compile } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_user 'appserver' } - it { is_expected.to contain_group 'jboss' } end + context 'with download_url => file:///tmp/wildfly-8.2.0.Final.zip set' do let(:params) do { :download_url => 'file:///tmp/wildfly-8.2.0.Final.zip' } @@ -73,5 +80,6 @@ it { is_expected.to contain_class 'jboss::internal::compatibility' } it { is_expected.to contain_class 'jboss::internal::configuration' } it { is_expected.to contain_class 'jboss::internal::service' } + end end diff --git a/spec/spec_helper_puppet.rb b/spec/spec_helper_puppet.rb index aee5ce4..6ccae2b 100644 --- a/spec/spec_helper_puppet.rb +++ b/spec/spec_helper_puppet.rb @@ -6,4 +6,9 @@ module JBoss end end require 'testing/jboss/shared_examples' +module Testing + module RspecPuppet end +end +require 'testing/rspec_puppet/package' + at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/testing/rspec_puppet/package.rb b/spec/testing/rspec_puppet/package.rb new file mode 100644 index 0000000..0b8d748 --- /dev/null +++ b/spec/testing/rspec_puppet/package.rb @@ -0,0 +1,36 @@ +module Testing::RspecPuppet::Package + DEFAULT_VERSION = '8.2.0.Final' + DEFAULT_PRODUCT = 'wildfly' + + DEFAULT_OPTIONS = { + :product => DEFAULT_PRODUCT, + :version => DEFAULT_VERSION + } + def package_files_for_jboss_product(options = DEFAULT_OPTIONS) + without = options[:without] || [] + with = [with] unless with.is_a? Array + with = with.reject { |el| without.include? el } + version = options[:version] || DEFAULT_VERSION + product = options[:product] || DEFAULT_PRODUCT + describe "with package files for #{product}" do + it { is_expected.to contain_file("/etc/#{product}").with({ + :ensure => 'directory', + :alias => 'jboss::confdir', + :owner => 'root', + :group => 'root', + :mode => '0755' + })} + it { is_expected.to contain_file("/usr/src/download-#{product}-#{version}"). + with_ensure('directory')} + it { is_expected.to contain_jboss__internal__util__fetch__file('wildfly-8.2.0.Final.zip').with({ + :address => 'http://download.jboss.org/wildfly/8.2.0.Final/wildfly-8.2.0.Final.zip', + :fetch_dir => "/usr/src/download-#{product}-#{version}"}). + that_requires("File[/usr/src/download-#{product}-#{version}]")} + it { is_expected.to contain_jboss__internal__util__groupaccess("/usr/lib/#{product}-#{version}") } + it { is_expected.to contain_file("/etc/#{product}/domain.xml") } + it { is_expected.to contain_file("/etc/#{product}/host.xml") } + it { is_expected.to contain_file("/etc/#{product}/standalone.xml") } + it { is_expected.to contain_file("/etc/init.d/#{product}") } + end + end +end