diff --git a/spec/acceptance/agent_spec.rb b/spec/acceptance/agent_spec.rb index 0c469e94..77f68ad3 100644 --- a/spec/acceptance/agent_spec.rb +++ b/spec/acceptance/agent_spec.rb @@ -4,48 +4,50 @@ supported_versions.each do |version| describe "zabbix::agent class with zabbix_version #{version}" do - it 'works idempotently with no errors' do - pp = <<-EOS - class { 'zabbix::agent': - server => '192.168.20.11', - zabbix_package_state => 'latest', - zabbix_version => '#{version}', - } - EOS - + before(:all) do prepare_host - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) end - # do some basic checks - describe package('zabbix-agent') do - it { is_expected.to be_installed } - end + context 'With minimal parameter' do + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'zabbix::agent': + server => '192.168.20.11', + zabbix_package_state => 'latest', + zabbix_version => '#{version}', + } + PUPPET + end + end - describe service('zabbix-agent') do - it { is_expected.to be_running } - it { is_expected.to be_enabled } - end + # do some basic checks + describe package('zabbix-agent') do + it { is_expected.to be_installed } + end - describe file('/etc/zabbix/zabbix_agentd.conf') do - its(:content) { is_expected.not_to match %r{ListenIP=} } + describe service('zabbix-agent') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + + describe file('/etc/zabbix/zabbix_agentd.conf') do + its(:content) { is_expected.not_to match %r{ListenIP=} } + end end context 'With ListenIP set to an IP-Address' do - it 'works idempotently with no errors' do - pp = <<-EOS + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET class { 'zabbix::agent': server => '192.168.20.11', zabbix_package_state => 'latest', listenip => '127.0.0.1', zabbix_version => '#{version}', } - EOS - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + PUPPET + end end describe file('/etc/zabbix/zabbix_agentd.conf') do @@ -54,36 +56,21 @@ class { 'zabbix::agent': end context 'With ListenIP set to lo' do - it 'works idempotently with no errors' do - pp = <<-EOS + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET class { 'zabbix::agent': server => '192.168.20.11', zabbix_package_state => 'latest', listenip => 'lo', zabbix_version => '#{version}', } - EOS - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - context 'With ListenIP set to an IP-Address' do - it 'works idempotently with no errors' do - pp = <<-EOS - class { 'zabbix::agent': - server => '192.168.20.11', - zabbix_package_state => 'latest', - listenip => '127.0.0.1', - zabbix_version => '#{version}', - } - EOS - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + PUPPET end + end - describe file('/etc/zabbix/zabbix_agentd.conf') do - its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} } - end + describe file('/etc/zabbix/zabbix_agentd.conf') do + its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} } end end end diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index a7821a90..46204be6 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -2,9 +2,12 @@ require 'spec_helper_acceptance' describe 'zabbix::server class', unless: default[:platform] =~ %r{archlinux} do + before(:all) do + prepare_host + end + context 'default parameters' do - # Using puppet_apply as a helper - it 'works idempotently with no errors' do + it_behaves_like 'an idempotent resource' do # this is a minimal working example if you've a postgres server # running on another node. multinode testing with beaker is pain, # so we will deploy multiple services into one box @@ -15,16 +18,12 @@ # EOS # this will actually deploy apache + postgres + zabbix-server + zabbix-web - pp = <<-EOS + let(:manifest) do + <<-PUPPET class { 'zabbix::database': } -> class { 'zabbix::server': } - EOS - - prepare_host - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + PUPPET + end end # do some basic checks @@ -47,8 +46,7 @@ class { 'zabbix::database': } next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} context "deploys a zabbix #{zabbix_version} server" do - # Using puppet_apply as a helper - it 'works idempotently with no errors' do + it_behaves_like 'an idempotent resource' do # this is a minimal working example if you've a postgres server # running on another node. multinode testing with beaker is pain, # so we will deploy multiple services into one box @@ -57,20 +55,15 @@ class { 'zabbix::database': } # manage_database => false, # } # EOS - # this will actually deploy apache + postgres + zabbix-server + zabbix-web - pp = <<-EOS + let(:manifest) do + <<-PUPPET class { 'zabbix::database': } -> class { 'zabbix::server': zabbix_version => "#{zabbix_version}" } - EOS - - prepare_host - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + PUPPET + end end # do some basic checks diff --git a/spec/acceptance/zabbix_proxy_spec.rb b/spec/acceptance/zabbix_proxy_spec.rb index d57f2697..edf7a74d 100644 --- a/spec/acceptance/zabbix_proxy_spec.rb +++ b/spec/acceptance/zabbix_proxy_spec.rb @@ -40,22 +40,20 @@ class { 'zabbix': end # setup proxies within zabbix - pp2 = <<-EOS - zabbix_proxy { 'ZabbixProxy1': - mode => 0, - } - zabbix_proxy { 'ZabbixProxy2': - ipaddress => '127.0.0.3', - use_ip => false, - mode => 1, - port => 10055, - } - EOS - - it 'works idempotently with no errors' do - # Run it twice and test for idempotency - apply_manifest(pp2, catch_failures: true) - apply_manifest(pp2, catch_changes: true) + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + zabbix_proxy { 'ZabbixProxy1': + mode => 0, + } + zabbix_proxy { 'ZabbixProxy2': + ipaddress => '127.0.0.3', + use_ip => false, + mode => 1, + port => 10055, + } + PUPPET + end end let(:result_proxies) do @@ -102,22 +100,20 @@ class { 'zabbix': context 'update zabbix_proxy resources' do # This will update the Zabbix proxies created above by switching their configuration - pp_update = <<-EOS - zabbix_proxy { 'ZabbixProxy1': - ipaddress => '127.0.0.3', - use_ip => false, - mode => 1, - port => 10055, - } - zabbix_proxy { 'ZabbixProxy2': - mode => 0, - } - EOS - - it 'works idempotently with no errors' do - # Run it twice and test for idempotency - apply_manifest(pp_update, catch_failures: true) - apply_manifest(pp_update, catch_changes: true) + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + zabbix_proxy { 'ZabbixProxy1': + ipaddress => '127.0.0.3', + use_ip => false, + mode => 1, + port => 10055, + } + zabbix_proxy { 'ZabbixProxy2': + mode => 0, + } + PUPPET + end end let(:result_proxies) do @@ -164,19 +160,17 @@ class { 'zabbix': context 'delete zabbix_proxy resources' do # This will delete the Zabbix proxies create above - pp_delete = <<-EOS - zabbix_proxy { 'ZabbixProxy1': - ensure => absent, - } - zabbix_proxy { 'ZabbixProxy2': - ensure => absent, - } - EOS - - it 'works idempotently with no errors' do - # Run it twice and test for idempotency - apply_manifest(pp_delete, catch_failures: true) - apply_manifest(pp_delete, catch_changes: true) + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + zabbix_proxy { 'ZabbixProxy1': + ensure => absent, + } + zabbix_proxy { 'ZabbixProxy2': + ensure => absent, + } + PUPPET + end end let(:result_proxies) do