From 1d40fc7a98303ae03ea0871e01c5392719929942 Mon Sep 17 00:00:00 2001 From: Radoslaw Frackiewicz Date: Thu, 4 Feb 2016 08:35:35 +0100 Subject: [PATCH 1/5] #45 rspec tests for lenses and augeas --- spec/classes/internal/augeas_spec.rb | 93 ++++++++++++++++++++++++++++ spec/classes/internal/lenses_spec.rb | 51 +++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 spec/classes/internal/augeas_spec.rb create mode 100644 spec/classes/internal/lenses_spec.rb diff --git a/spec/classes/internal/augeas_spec.rb b/spec/classes/internal/augeas_spec.rb new file mode 100644 index 0000000..dcfb87e --- /dev/null +++ b/spec/classes/internal/augeas_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::augeas', :type => :class do + wildfly = '8.2.0.Final' + bind_variables_list = [ + "inet-address", "link-local-address", + "loopback", "loopback-address", "multicast", + "nic", "nic-match", "point-to-point", "public-address", + "site-local-address", "subnet-match", "up", "virtual", + "any-ipv4-address", "any-ipv6-address" ] + + anchor_list = [ + "begin", "end", "configuration::begin", "configuration::end", + "installed", "package::begin", "package::end", + "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} + + shared_examples 'completly working define' do + it { is_expected.to compile } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_class 'jboss::internal::lenses' } + it { is_expected.to contain_class 'jboss::internal::augeas' } + + it { is_expected.to contain_jboss__interface('public').with ({ + :ensure => 'present', + :inet_address => nil + }) } + it { is_expected.to contain_augeas('ensure present interface public').with ({ + :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", + :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" + }) } + it { is_expected.to contain_augeas('interface public set any-address').with ({ + :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", + :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with ({ + :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + + anchor_list.each do |item| + it { is_expected.to contain_anchor("#{item}") } + end + + bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface public rm #{var}").with ({ + :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", + :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", + :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with ({ + :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + end + it { is_expected.to contain_service('wildfly').with ({ + :ensure => 'running', + :enable => true + }) } + + it { is_expected.to contain_file("/usr/lib/wildfly-8.2.0.Final/lenses/jbxml.aug") } + end + + context 'On RedHat os family' do + let(:title) { 'test-augeas' } + let(:facts) do + { + :operatingsystem => 'OracleLinux', + :osfamily => 'RedHat', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end + + context 'On Debian os family' do + let(:title) { 'test-augeas' } + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :lsbdistcodename => 'trusty', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end +end diff --git a/spec/classes/internal/lenses_spec.rb b/spec/classes/internal/lenses_spec.rb new file mode 100644 index 0000000..11d6897 --- /dev/null +++ b/spec/classes/internal/lenses_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::lenses', :type => :class do + shared_examples 'completly working define' do + it { is_expected.to contain_class 'jboss::internal::lenses' } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses/jbxml.aug').with({ + :ensure => 'file', + :source => 'puppet:///modules/jboss/jbxml.aug', + }) } + it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses/jbxml.aug').that_requires( + 'File[/usr/lib/wildfly-8.2.0.Final/lenses/]' + )} + it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses').with ({ + :ensure => 'directory', + :owner => 'jboss', + }) } + it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses').that_requires( + 'Anchor[jboss::configuration::begin]' + )} + end + + context 'On RedHat os family' do + let(:title) { 'test-lenses' } + let(:facts) do + { + :operatingsystem => 'OracleLinux', + :osfamily => 'RedHat', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end + + context 'On Debian os family' do + let(:title) { 'test-lenses' } + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :lsbdistcodename => 'trusty', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end +end From 0158c42e5a2dc6004a1aa10600e36c09f31a6a6f Mon Sep 17 00:00:00 2001 From: Radoslaw Frackiewicz Date: Thu, 4 Feb 2016 15:54:05 +0100 Subject: [PATCH 2/5] #45 add tests for new clas:configuration --- spec/classes/internal/augeas_spec.rb | 14 ++--- spec/classes/internal/configuration_spec.rb | 58 +++++++++++++++++++++ spec/classes/internal/lenses_spec.rb | 2 +- 3 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 spec/classes/internal/configuration_spec.rb diff --git a/spec/classes/internal/augeas_spec.rb b/spec/classes/internal/augeas_spec.rb index dcfb87e..86315ee 100644 --- a/spec/classes/internal/augeas_spec.rb +++ b/spec/classes/internal/augeas_spec.rb @@ -20,21 +20,21 @@ it { is_expected.to contain_class 'jboss::internal::lenses' } it { is_expected.to contain_class 'jboss::internal::augeas' } - it { is_expected.to contain_jboss__interface('public').with ({ + it { is_expected.to contain_jboss__interface('public').with({ :ensure => 'present', :inet_address => nil }) } - it { is_expected.to contain_augeas('ensure present interface public').with ({ + it { is_expected.to contain_augeas('ensure present interface public').with({ :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" }) } - it { is_expected.to contain_augeas('interface public set any-address').with ({ + it { is_expected.to contain_augeas('interface public set any-address').with({ :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with ({ + it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", :path => 'server/interfaces' }) } @@ -44,17 +44,17 @@ end bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with ({ + it { is_expected.to contain_augeas("interface public rm #{var}").with({ :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with ({ + it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", :path => 'server/interfaces' }) } end - it { is_expected.to contain_service('wildfly').with ({ + it { is_expected.to contain_service('wildfly').with({ :ensure => 'running', :enable => true }) } diff --git a/spec/classes/internal/configuration_spec.rb b/spec/classes/internal/configuration_spec.rb new file mode 100644 index 0000000..43e52f2 --- /dev/null +++ b/spec/classes/internal/configuration_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::configuration', :type => :class do + shared_examples 'completly working define' do + it { is_expected.to compile } + it { is_expected.to contain_class 'jboss::internal::configuration' } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_class 'jboss::params' } + it { is_expected.to contain_class 'jboss::internal::params' } + it { is_expected.to contain_class 'jboss::internal::runtime' } + it { is_expected.to contain_class 'jboss::internal::augeas' } + it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } + it { is_expected.to contain_class 'jboss::internal::quirks::etc_initd_functions' } + it { is_expected.to contain_class 'jboss::internal::service' } + + it { is_expected.to contain_file('/etc/profile.d/jboss.sh').with({ + :ensure => 'file', + :mode => '0644' + }) } + + it { is_expected.to contain_file('/var/log/wildfly/console.log').with({ + :ensure => 'file', + :alias => 'jboss::logfile', + :owner => 'root', + :group => 'jboss', + :mode => '0660' + }) } + end + + context 'On RedHat os family' do + let(:title) { 'test-configuration' } + let(:facts) do + { + :operatingsystem => 'OracleLinux', + :osfamily => 'RedHat', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end + + context 'On Debian os family' do + let(:title) { 'test-configuration' } + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :lsbdistcodename => 'trusty', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + end +end diff --git a/spec/classes/internal/lenses_spec.rb b/spec/classes/internal/lenses_spec.rb index 11d6897..5e65424 100644 --- a/spec/classes/internal/lenses_spec.rb +++ b/spec/classes/internal/lenses_spec.rb @@ -11,7 +11,7 @@ it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses/jbxml.aug').that_requires( 'File[/usr/lib/wildfly-8.2.0.Final/lenses/]' )} - it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses').with ({ + it { is_expected.to contain_file('/usr/lib/wildfly-8.2.0.Final/lenses').with({ :ensure => 'directory', :owner => 'jboss', }) } From dea70676ce95e454e9d414530ffb9230c5eb29b4 Mon Sep 17 00:00:00 2001 From: Radoslaw Frackiewicz Date: Fri, 5 Feb 2016 11:24:43 +0100 Subject: [PATCH 3/5] #45 add shared examples for common files: anchors, interfaces --- spec/shared_examples.rb | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 spec/shared_examples.rb diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb new file mode 100644 index 0000000..5e18517 --- /dev/null +++ b/spec/shared_examples.rb @@ -0,0 +1,79 @@ +module Testing::JBoss::SharedExamples + + def working_jboss_installation + name = "working jboss installation" + shared_examples(name) do + it { is_expected.to compile } + it { is_expected.to contain_user 'jboss' } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_group 'jboss' } + it { is_expected.to contain_package 'wget' } + it { is_expected.to contain_class 'jboss::internal::service' } + it { is_expected.to contain_class 'jboss::internal::runtime::node' } + it { is_expected.to contain_class 'jboss::params' } + it { is_expected.to contain_class 'jboss::internal::runtime::dc' } + end + name + end + + def common_anchors + anchor_list = [ + "begin", "end", "configuration::begin", "configuration::end", + "installed", "package::begin", "package::end", + "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} + name = 'having common anchors' + shared_examples(name) do + anchor_list.each do |item| + it { is_expected.to contain_anchor("#{item}") } + end + end + name + end + + def common_interfaces(version) + bind_variables_list = [ + "inet-address", "link-local-address", + "loopback", "loopback-address", "multicast", + "nic", "nic-match", "point-to-point", "public-address", + "site-local-address", "subnet-match", "up", "virtual", + "any-ipv4-address", "any-ipv6-address" ] + name = 'common interfaces' + shared_examples(name) do + it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } + it { is_expected.to contain_jboss__interface('public').with({ + :ensure => 'present', + :inet_address => nil + }) } + it { is_expected.to contain_augeas('ensure present interface public').with({ + :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", + :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" + }) } + it { is_expected.to contain_augeas('interface public set any-address').with({ + :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", + :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ + :cfg_file => "/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + it { is_expected.to contain_service('wildfly').with({ + :ensure => 'running', + :enable => true + }) } + bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface public rm #{var}").with({ + :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", + :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ + :cfg_file => "/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + end + end + name + end +end From b7f6d7b8ce096033209a21a1b75fa6ff12e51276 Mon Sep 17 00:00:00 2001 From: Radoslaw Frackiewicz Date: Fri, 5 Feb 2016 14:54:08 +0100 Subject: [PATCH 4/5] #45 change in rspec test structure --- spec/classes/internal/augeas_spec.rb | 62 ++------------ spec/classes/internal/configuration_spec.rb | 43 ++++++++-- spec/defines/clientry_spec.rb | 91 ++++++--------------- spec/shared_examples.rb | 5 +- spec/spec_helper_puppet.rb | 4 + 5 files changed, 74 insertions(+), 131 deletions(-) diff --git a/spec/classes/internal/augeas_spec.rb b/spec/classes/internal/augeas_spec.rb index 86315ee..3415224 100644 --- a/spec/classes/internal/augeas_spec.rb +++ b/spec/classes/internal/augeas_spec.rb @@ -1,68 +1,15 @@ require 'spec_helper_puppet' describe 'jboss::internal::augeas', :type => :class do - wildfly = '8.2.0.Final' - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} shared_examples 'completly working define' do - it { is_expected.to compile } - it { is_expected.to contain_class 'jboss' } it { is_expected.to contain_class 'jboss::internal::lenses' } it { is_expected.to contain_class 'jboss::internal::augeas' } - - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", - :path => 'server/interfaces' - }) } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => "/files/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml/", - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => "/usr/lib/wildfly-#{wildfly}/standalone/configuration/standalone-full.xml", - :path => 'server/interfaces' - }) } - end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true - }) } - it { is_expected.to contain_file("/usr/lib/wildfly-8.2.0.Final/lenses/jbxml.aug") } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-augeas' } let(:facts) do { @@ -74,9 +21,13 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-augeas' } let(:facts) do { @@ -89,5 +40,8 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') end end diff --git a/spec/classes/internal/configuration_spec.rb b/spec/classes/internal/configuration_spec.rb index 43e52f2..b81b3ab 100644 --- a/spec/classes/internal/configuration_spec.rb +++ b/spec/classes/internal/configuration_spec.rb @@ -2,17 +2,9 @@ describe 'jboss::internal::configuration', :type => :class do shared_examples 'completly working define' do - it { is_expected.to compile } it { is_expected.to contain_class 'jboss::internal::configuration' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss::internal::params' } - it { is_expected.to contain_class 'jboss::internal::runtime' } - it { is_expected.to contain_class 'jboss::internal::augeas' } it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } it { is_expected.to contain_class 'jboss::internal::quirks::etc_initd_functions' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_file('/etc/profile.d/jboss.sh').with({ :ensure => 'file', :mode => '0644' @@ -25,9 +17,35 @@ :group => 'jboss', :mode => '0660' }) } + + it { is_expected.to contain_file('/etc/jboss-as').with({ + :ensure => 'directory', + :mode => '2770', + :owner => 'jboss', + :group => 'jboss' + }) } + + it { is_expected.to contain_file('/etc/jboss-as/jboss-as.conf'). + with_ensure('link'). + that_comes_before('Anchor[jboss::configuration::end]') } + + it { is_expected.to contain_file('/etc/default').with_ensure('directory') } + + it { is_expected.to contain_file('/etc/default/wildfly.conf'). + with_ensure('link'). + that_comes_before('Anchor[jboss::configuration::end]') } + + it { is_expected.to contain_concat('/etc/wildfly/wildfly.conf').with({ + :alias => 'jboss::jboss-as.conf', + :mode => '0644' + }) } + it { is_expected.to contain_concat__fragment('jboss::jboss-as.conf::defaults').with({ + :order => '000' + }) } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-configuration' } let(:facts) do { @@ -39,9 +57,14 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') + it { is_expected.to contain_file('/etc/sysconfig/wildfly.conf') } end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-configuration' } let(:facts) do { @@ -54,5 +77,9 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') + it { is_expected.to contain_file('/etc/default/wildfly') } end end diff --git a/spec/defines/clientry_spec.rb b/spec/defines/clientry_spec.rb index c7946ef..0ec9f6a 100644 --- a/spec/defines/clientry_spec.rb +++ b/spec/defines/clientry_spec.rb @@ -1,79 +1,26 @@ require 'spec_helper_puppet' describe 'jboss::clientry', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} shared_examples 'completly working define' do - it { is_expected.to compile } - it { is_expected.to contain_jboss_confignode(title).with({ - :ensure => 'present', - :path => 'profile/test' - }) } - - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::runtime::node' } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss::internal::runtime::dc' } - it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } - it { is_expected.to contain_jboss_confignode(title).that_requires('Anchor[jboss::package::end]') } - it { is_expected.to contain_jboss__clientry(title).with({ - :ensure => 'present', - :path => 'profile/test', - }) } - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } + it do + is_expected.to contain_jboss_confignode(title).with({ + :ensure => 'present', + :path => 'profile/test' + }) end - - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } + it { is_expected.to contain_jboss_confignode(title).that_requires('Anchor[jboss::package::end]') } + it do + is_expected.to contain_jboss__clientry(title).with({ + :ensure => 'present', + :path => 'profile/test', + }) end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true - }) } end - context 'On RedHat os family' do + context 'on RedHat os family' do + extend Testing::JBoss::SharedExamples + let(:title) { 'test-clientry' } let(:params) { { :path => 'profile/test', } } let(:facts) do @@ -86,9 +33,14 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') end - context 'On Debian os family' do + context 'on Debian os family' do + extend Testing::JBoss::SharedExamples + let(:title) { 'test-clientry' } let(:params) { { :path => 'profile/test', } } let(:facts) do @@ -102,5 +54,8 @@ } end it_behaves_like 'completly working define' + it_behaves_like working_jboss_installation + it_behaves_like common_anchors + it_behaves_like common_interfaces('8.2.0.Final') end end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 5e18517..d3c6346 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -8,9 +8,12 @@ def working_jboss_installation it { is_expected.to contain_class 'jboss' } it { is_expected.to contain_group 'jboss' } it { is_expected.to contain_package 'wget' } + it { is_expected.to contain_package 'unzip' } it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::runtime::node' } it { is_expected.to contain_class 'jboss::params' } + it { is_expected.to contain_class 'jboss::internal::runtime' } + it { is_expected.to contain_class 'jboss::internal::augeas' } + it { is_expected.to contain_class 'jboss::internal::params' } it { is_expected.to contain_class 'jboss::internal::runtime::dc' } end name diff --git a/spec/spec_helper_puppet.rb b/spec/spec_helper_puppet.rb index 8d74cb0..2fd3518 100644 --- a/spec/spec_helper_puppet.rb +++ b/spec/spec_helper_puppet.rb @@ -1,5 +1,9 @@ $executing_puppet = true require 'spec_helper' +module Testing + module JBoss end +end +require 'shared_examples' at_exit { RSpec::Puppet::Coverage.report! } From f960a3e5b4d8064883773c3535d1606a9e336616 Mon Sep 17 00:00:00 2001 From: Radoslaw Frackiewicz Date: Mon, 8 Feb 2016 15:48:18 +0100 Subject: [PATCH 5/5] #45 change in rspec test structure; rebuild shared_examples --- spec/classes/internal/augeas_spec.rb | 10 +-- spec/classes/internal/configuration_spec.rb | 8 +- .../internal/configure/interfaces_spec.rb | 61 ++------------- .../quirks/etc_initd_functions_spec.rb | 12 +-- spec/classes/internal/service_spec.rb | 37 +--------- spec/defines/clientry_spec.rb | 8 +- spec/defines/deploy_spec.rb | 74 +++---------------- spec/defines/interface_spec.rb | 28 +++---- spec/defines/jmsqueue_spec.rb | 18 +++-- spec/defines/module_spec.rb | 55 +------------- spec/defines/resourceadapter_spec.rb | 67 ++--------------- spec/defines/securitydomain_spec.rb | 23 +++++- spec/spec_helper_puppet.rb | 2 +- spec/{ => testing/jboss}/shared_examples.rb | 50 ++++++++++--- 14 files changed, 128 insertions(+), 325 deletions(-) rename spec/{ => testing/jboss}/shared_examples.rb (65%) diff --git a/spec/classes/internal/augeas_spec.rb b/spec/classes/internal/augeas_spec.rb index 3415224..848a559 100644 --- a/spec/classes/internal/augeas_spec.rb +++ b/spec/classes/internal/augeas_spec.rb @@ -21,9 +21,8 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation + end context 'On Debian os family' do @@ -40,8 +39,7 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation + end end diff --git a/spec/classes/internal/configuration_spec.rb b/spec/classes/internal/configuration_spec.rb index b81b3ab..f96d087 100644 --- a/spec/classes/internal/configuration_spec.rb +++ b/spec/classes/internal/configuration_spec.rb @@ -57,9 +57,7 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation it { is_expected.to contain_file('/etc/sysconfig/wildfly.conf') } end @@ -77,9 +75,7 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation it { is_expected.to contain_file('/etc/default/wildfly') } end end diff --git a/spec/classes/internal/configure/interfaces_spec.rb b/spec/classes/internal/configure/interfaces_spec.rb index 3b29c95..cb94740 100644 --- a/spec/classes/internal/configure/interfaces_spec.rb +++ b/spec/classes/internal/configure/interfaces_spec.rb @@ -1,67 +1,13 @@ require 'spec_helper_puppet' describe 'jboss::internal::configure::interfaces', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} - shared_examples 'completly working define' do - it { is_expected.to compile } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss::internal::runtime::dc' } it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true - }) } end context 'On RedHat os family' do let(:title) { 'test-conf-interfaces' } + extend Testing::JBoss::SharedExamples let(:facts) do { :operatingsystem => 'OracleLinux', @@ -72,10 +18,12 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do - let(:title) { 'test-module' } + extend Testing::JBoss::SharedExamples + let(:title) { 'test-conf-interfaces' } let(:facts) do { :operatingsystem => 'Ubuntu', @@ -87,5 +35,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/classes/internal/quirks/etc_initd_functions_spec.rb b/spec/classes/internal/quirks/etc_initd_functions_spec.rb index 3afb733..5808c36 100644 --- a/spec/classes/internal/quirks/etc_initd_functions_spec.rb +++ b/spec/classes/internal/quirks/etc_initd_functions_spec.rb @@ -2,14 +2,11 @@ describe 'jboss::internal::quirks::etc_initd_functions', :type => :define do shared_examples 'completly working define' do - it { is_expected.to compile } it { is_expected.to contain_class 'jboss::internal::quirks::etc_initd_functions' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::compatibility' } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-etc_initd_functions' } let(:facts) do { @@ -21,10 +18,13 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation + end context 'On Debian os family' do - let(:title) { 'test-module' } + extend Testing::JBoss::SharedExamples + let(:title) { 'test-etc_initd_functions' } let(:facts) do { :operatingsystem => 'Ubuntu', @@ -36,5 +36,7 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation + end end diff --git a/spec/classes/internal/service_spec.rb b/spec/classes/internal/service_spec.rb index 9b5203f..30256b9 100644 --- a/spec/classes/internal/service_spec.rb +++ b/spec/classes/internal/service_spec.rb @@ -1,45 +1,13 @@ require 'spec_helper_puppet' describe 'jboss::internal::service', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} - shared_examples 'completly working define' do - it { is_expected.to compile } it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss::internal::configuration' } - it { is_expected.to contain_jboss__interface('public') } - it { is_expected.to contain_augeas('ensure present interface public') } - it { is_expected.to contain_augeas('interface public set any-address') } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}") } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}") } - end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true - })} it { is_expected.to contain_exec('jboss::move-unzipped') } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-service' } let(:facts) do { @@ -51,9 +19,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-module' } let(:facts) do { @@ -66,5 +36,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/clientry_spec.rb b/spec/defines/clientry_spec.rb index 0ec9f6a..48819e3 100644 --- a/spec/defines/clientry_spec.rb +++ b/spec/defines/clientry_spec.rb @@ -33,9 +33,7 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation end context 'on Debian os family' do @@ -54,8 +52,6 @@ } end it_behaves_like 'completly working define' - it_behaves_like working_jboss_installation - it_behaves_like common_anchors - it_behaves_like common_interfaces('8.2.0.Final') + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/deploy_spec.rb b/spec/defines/deploy_spec.rb index 6a8a7e1..00a91b9 100644 --- a/spec/defines/deploy_spec.rb +++ b/spec/defines/deploy_spec.rb @@ -1,77 +1,18 @@ require 'spec_helper_puppet' describe 'jboss::deploy', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} - shared_examples 'completly working define' do - it { is_expected.to compile } it { is_expected.to contain_jboss__deploy(title).with({ - :ensure => 'present', - :path => '/tmp/jboss.war', - :servergroups => '' + :ensure => 'present', + :jndi => title }) } it { is_expected.to contain_jboss_deploy(title).with({ - :ensure => 'present', - :source => '/tmp/jboss.war', - :redeploy => false - }) } - it { is_expected.to contain_jboss_deploy(title).that_requires('Exec[jboss::service::restart]') } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_class 'jboss::params' } - it {is_expected.to contain_class 'jboss::internal::runtime::node' } - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true + :ensure => 'present', + :source => '/tmp/jboss.war' }) } - end - +end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-deploy' } let(:params) { { :path => '/tmp/jboss.war', } } let(:facts) do @@ -84,9 +25,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-deploy' } let(:params) { { :path => '/tmp/jboss.war', } } let(:facts) do @@ -100,6 +43,7 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/interface_spec.rb b/spec/defines/interface_spec.rb index 942702d..c615c52 100644 --- a/spec/defines/interface_spec.rb +++ b/spec/defines/interface_spec.rb @@ -9,28 +9,17 @@ "any-ipv4-address", "any-ipv6-address" ] shared_examples 'completly working define' do - it { is_expected.to compile } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_class 'jboss::internal::augeas' } - it { is_expected.to contain_class 'jboss::internal::runtime' } it { is_expected.to contain_jboss__interface(title) } - it { is_expected.to contain_jboss__interface('public') } + it { is_expected.to contain_jboss__internal__interface__foreach('test-interface:any-address') } + it { is_expected.to contain_augeas('ensure present interface test-interface') } + it { is_expected.to contain_augeas('interface test-interface set any-address') } bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface #{title} rm #{var}") } - it { is_expected.to contain_augeas("interface public rm #{var}") } - it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}")} - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}")} - end - it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:any-address")} - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address")} - it { is_expected.to contain_augeas("ensure present interface #{title}") } - it { is_expected.to contain_augeas("ensure present interface public") } - it { is_expected.to contain_augeas("interface #{title} set any-address") } - it { is_expected.to contain_augeas("interface public set any-address") } - + it { is_expected.to contain_augeas("interface test-interface rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("test-interface:#{var}") } + end end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-interface' } let(:facts) do { @@ -47,9 +36,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-interface' } let(:facts) do { @@ -67,5 +58,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/jmsqueue_spec.rb b/spec/defines/jmsqueue_spec.rb index 88a2783..ff47446 100644 --- a/spec/defines/jmsqueue_spec.rb +++ b/spec/defines/jmsqueue_spec.rb @@ -2,21 +2,24 @@ describe 'jboss::jmsqueue', :type => :define do shared_examples 'completly working define' do - it { is_expected.to compile } it { is_expected.to contain_jboss_jmsqueue(title).with({ :ensure => 'present', :entries => [ 'queue/app-mails', 'java:jboss/exported/jms/queue/app-mails'] }) } - it { is_expected.to contain_jboss_jmsqueue(title).that_requires('Anchor[jboss::package::end]') } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::runtime::node' } - it { is_expected.to contain_jboss__jmsqueue(title) } + it { is_expected.to contain_jboss_jmsqueue(title). + that_requires('Anchor[jboss::package::end]') } + it { is_expected.to contain_jboss__jmsqueue(title).with({ + :ensure => 'present', + :entries => [ + 'queue/app-mails', + 'java:jboss/exported/jms/queue/app-mails'] + }) } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-jmsqueue' } let(:params) { { :entries => [ 'queue/app-mails', @@ -31,9 +34,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-jmsqueue' } let(:params) { { :entries => [ 'queue/app-mails', @@ -49,5 +54,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/module_spec.rb b/spec/defines/module_spec.rb index 6547c64..3cee1c5 100644 --- a/spec/defines/module_spec.rb +++ b/spec/defines/module_spec.rb @@ -1,70 +1,20 @@ require 'spec_helper_puppet' describe 'jboss::module', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} - shared_examples 'completly working define' do - 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' } - it { is_expected.to contain_class 'jboss::params' } it { is_expected.to contain_jboss__internal__module__assemble(title).with({ :layer => 'jdbc', :artifacts => ["https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar"], :dependencies => ["javax.transaction.api", "javax.api"] })} - it { is_expected.to contain_jboss__module(title).with({ :layer => 'jdbc', :artifacts => ["https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar"] }) } - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - end - - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-module' } let(:params) do { @@ -83,9 +33,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-module' } let(:params) do { @@ -105,5 +57,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/resourceadapter_spec.rb b/spec/defines/resourceadapter_spec.rb index daf7c17..ad753d0 100644 --- a/spec/defines/resourceadapter_spec.rb +++ b/spec/defines/resourceadapter_spec.rb @@ -1,79 +1,24 @@ require 'spec_helper_puppet' describe 'jboss::resourceadapter', :type => :define do - bind_variables_list = [ - "inet-address", "link-local-address", - "loopback", "loopback-address", "multicast", - "nic", "nic-match", "point-to-point", "public-address", - "site-local-address", "subnet-match", "up", "virtual", - "any-ipv4-address", "any-ipv6-address" ] - - anchor_list = [ - "begin", "end", "configuration::begin", "configuration::end", - "installed", "package::begin", "package::end", - "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} - shared_examples 'completly working define' do - it { is_expected.to compile } + it { is_expected.to contain_jboss_resourceadapter(title).with({ :ensure => 'present', :archive => 'jca-filestore.rar' })} - it { is_expected.to contain_jboss_resourceadapter(title).that_requires('Anchor[jboss::package::end]') } - it { is_expected.to contain_user 'jboss' } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_class 'jboss::params' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::runtime::node' } + it { is_expected.to contain_jboss_resourceadapter(title). + that_requires('Anchor[jboss::package::end]') } it { is_expected.to contain_jboss__resourceadapter(title).with({ :ensure => 'present', :archive => 'jca-filestore.rar', :transactionsupport => 'LocalTransaction', :classname => 'org.example.jca.FileSystemConnectionFactory', }) } - - it { is_expected.to contain_jboss__interface('public').with({ - :ensure => 'present', - :inet_address => nil - }) } - it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", - :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" - }) } - it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", - :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - - anchor_list.each do |item| - it { is_expected.to contain_anchor("#{item}") } - end - - bind_variables_list.each do |var| - it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => '/files/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml/', - :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", - :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" - }) } - it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => '/usr/lib/wildfly-8.2.0.Final/standalone/configuration/standalone-full.xml', - :path => 'server/interfaces' - }) } - end - it { is_expected.to contain_service('wildfly').with({ - :ensure => 'running', - :enable => true - }) } end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-resourceadapter' } let(:params) do { @@ -93,8 +38,11 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end + context 'On Debian os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-resourceadapter' } let(:params) do { @@ -115,5 +63,6 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/defines/securitydomain_spec.rb b/spec/defines/securitydomain_spec.rb index 08dd432..8247115 100644 --- a/spec/defines/securitydomain_spec.rb +++ b/spec/defines/securitydomain_spec.rb @@ -2,10 +2,6 @@ describe 'jboss::securitydomain', :type => :define do shared_examples 'completly working define' do - it { is_expected.to compile } - it { is_expected.to contain_class 'jboss' } - it { is_expected.to contain_class 'jboss::internal::service' } - it { is_expected.to contain_class 'jboss::internal::runtime::node' } it { is_expected.to contain_jboss_securitydomain(title).with({ :ensure => 'present' }) } @@ -13,6 +9,7 @@ end context 'On RedHat os family' do + extend Testing::JBoss::SharedExamples let(:title) { 'test-securitydomain' } let(:facts) do { @@ -24,5 +21,23 @@ } end it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation + end + + context 'On Debian os family' do + extend Testing::JBoss::SharedExamples + let(:title) { 'test-securitydomain' } + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :lsbdistcodename => 'trusty', + :puppetversion => Puppet.version + } + end + it_behaves_like 'completly working define' + it_behaves_like_full_working_jboss_installation end end diff --git a/spec/spec_helper_puppet.rb b/spec/spec_helper_puppet.rb index 2fd3518..aee5ce4 100644 --- a/spec/spec_helper_puppet.rb +++ b/spec/spec_helper_puppet.rb @@ -4,6 +4,6 @@ module Testing module JBoss end end -require 'shared_examples' +require 'testing/jboss/shared_examples' at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/shared_examples.rb b/spec/testing/jboss/shared_examples.rb similarity index 65% rename from spec/shared_examples.rb rename to spec/testing/jboss/shared_examples.rb index d3c6346..b56ad75 100644 --- a/spec/shared_examples.rb +++ b/spec/testing/jboss/shared_examples.rb @@ -1,4 +1,38 @@ module Testing::JBoss::SharedExamples + DEFAULT_VERSION = '8.2.0.Final' + DEFAULT_PRODUCT = 'wildfly' + DEFAULT_WITH = [ + :anchors, + :interfaces, + :packages + ] + DEFAULT_OPTIONS = { + :product => DEFAULT_PRODUCT, + :version => DEFAULT_VERSION, + :with => DEFAULT_WITH + } + + def it_behaves_like_full_working_jboss_installation(options = DEFAULT_OPTIONS) + without = options[:without] || [] + with = options[:with] || DEFAULT_WITH + with = [with] unless with.is_a? Array + with = with.reject { |el| without.include? el } + version = options[:version] || DEFAULT_VERSION + product = options[:product] || DEFAULT_PRODUCT + it_behaves_like working_jboss_installation + it_behaves_like containg_installation_packages if with.include? :packages + it_behaves_like common_anchors if with.include? :anchors + it_behaves_like common_interfaces(version, product) if with.include? :interfaces + end + + def containg_installation_packages + name = 'containing installation packages' + shared_examples(name) do + it { is_expected.to contain_package 'wget' } + it { is_expected.to contain_package 'unzip' } + end + name + end def working_jboss_installation name = "working jboss installation" @@ -7,8 +41,6 @@ def working_jboss_installation it { is_expected.to contain_user 'jboss' } it { is_expected.to contain_class 'jboss' } it { is_expected.to contain_group 'jboss' } - it { is_expected.to contain_package 'wget' } - it { is_expected.to contain_package 'unzip' } it { is_expected.to contain_class 'jboss::internal::service' } it { is_expected.to contain_class 'jboss::params' } it { is_expected.to contain_class 'jboss::internal::runtime' } @@ -33,7 +65,7 @@ def common_anchors name end - def common_interfaces(version) + def common_interfaces(version = DEFAULT_VERSION, product = DEFAULT_PRODUCT) bind_variables_list = [ "inet-address", "link-local-address", "loopback", "loopback-address", "multicast", @@ -48,31 +80,31 @@ def common_interfaces(version) :inet_address => nil }) } it { is_expected.to contain_augeas('ensure present interface public').with({ - :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" }) } it { is_expected.to contain_augeas('interface public set any-address').with({ - :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" }) } it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ - :cfg_file => "/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml", + :cfg_file => "/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml", :path => 'server/interfaces' }) } - it { is_expected.to contain_service('wildfly').with({ + it { is_expected.to contain_service(product).with({ :ensure => 'running', :enable => true }) } bind_variables_list.each do |var| it { is_expected.to contain_augeas("interface public rm #{var}").with({ - :context => "/files/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml/", + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" }) } it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ - :cfg_file => "/usr/lib/wildfly-#{version}/standalone/configuration/standalone-full.xml", + :cfg_file => "/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml", :path => 'server/interfaces' }) } end