Skip to content

Commit 3936467

Browse files
committed
Use shared example for indempotent resource
1 parent 934afa2 commit 3936467

File tree

3 files changed

+79
-107
lines changed

3 files changed

+79
-107
lines changed

spec/acceptance/agent_spec.rb

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
next if version < '6.0' && default[:platform] =~ %r{debian-12}
88

99
describe "zabbix::agent class with zabbix_version #{version}" do
10+
before(:all) do
11+
prepare_host
12+
end
13+
1014
context 'With minimal parameter' do
11-
it 'works idempotently with no errors' do
12-
pp = <<-EOS
13-
class { 'zabbix::agent':
14-
server => '192.168.20.11',
15-
zabbix_package_state => 'latest',
16-
zabbix_version => '#{version}',
17-
}
18-
EOS
19-
20-
prepare_host
21-
22-
# Run it twice and test for idempotency
23-
apply_manifest(pp, catch_failures: true)
24-
apply_manifest(pp, catch_changes: true)
15+
it_behaves_like 'an idempotent resource' do
16+
let(:manifest) do
17+
<<-PUPPET
18+
class { 'zabbix::agent':
19+
server => '192.168.20.11',
20+
zabbix_package_state => 'latest',
21+
zabbix_version => '#{version}',
22+
}
23+
PUPPET
24+
end
2525
end
2626

2727
# do some basic checks
@@ -40,17 +40,17 @@ class { 'zabbix::agent':
4040
end
4141

4242
context 'With ListenIP set to an IP-Address' do
43-
it 'works idempotently with no errors' do
44-
pp = <<-EOS
43+
it_behaves_like 'an idempotent resource' do
44+
let(:manifest) do
45+
<<-PUPPET
4546
class { 'zabbix::agent':
4647
server => '192.168.20.11',
4748
zabbix_package_state => 'latest',
4849
listenip => '127.0.0.1',
4950
zabbix_version => '#{version}',
5051
}
51-
EOS
52-
apply_manifest(pp, catch_failures: true)
53-
apply_manifest(pp, catch_changes: true)
52+
PUPPET
53+
end
5454
end
5555

5656
describe file('/etc/zabbix/zabbix_agentd.conf') do
@@ -59,36 +59,21 @@ class { 'zabbix::agent':
5959
end
6060

6161
context 'With ListenIP set to lo' do
62-
it 'works idempotently with no errors' do
63-
pp = <<-EOS
62+
it_behaves_like 'an idempotent resource' do
63+
let(:manifest) do
64+
<<-PUPPET
6465
class { 'zabbix::agent':
6566
server => '192.168.20.11',
6667
zabbix_package_state => 'latest',
6768
listenip => 'lo',
6869
zabbix_version => '#{version}',
6970
}
70-
EOS
71-
apply_manifest(pp, catch_failures: true)
72-
apply_manifest(pp, catch_changes: true)
73-
end
74-
75-
context 'With ListenIP set to an IP-Address' do
76-
it 'works idempotently with no errors' do
77-
pp = <<-EOS
78-
class { 'zabbix::agent':
79-
server => '192.168.20.11',
80-
zabbix_package_state => 'latest',
81-
listenip => '127.0.0.1',
82-
zabbix_version => '#{version}',
83-
}
84-
EOS
85-
apply_manifest(pp, catch_failures: true)
86-
apply_manifest(pp, catch_changes: true)
71+
PUPPET
8772
end
73+
end
8874

89-
describe file('/etc/zabbix/zabbix_agentd.conf') do
90-
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
91-
end
75+
describe file('/etc/zabbix/zabbix_agentd.conf') do
76+
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
9277
end
9378
end
9479
end

spec/acceptance/server_spec.rb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
require 'spec_helper_acceptance'
44
describe 'zabbix::server class', unless: default[:platform] =~ %r{archlinux} do
5+
before(:all) do
6+
prepare_host
7+
end
8+
59
context 'default parameters' do
6-
# Using puppet_apply as a helper
7-
it 'works idempotently with no errors' do
10+
it_behaves_like 'an idempotent resource' do
811
# this is a minimal working example if you've a postgres server
912
# running on another node. multinode testing with beaker is pain,
1013
# so we will deploy multiple services into one box
@@ -15,16 +18,12 @@
1518
# EOS
1619

1720
# this will actually deploy apache + postgres + zabbix-server + zabbix-web
18-
pp = <<-EOS
21+
let(:manifest) do
22+
<<-PUPPET
1923
class { 'zabbix::database': }
2024
-> class { 'zabbix::server': }
21-
EOS
22-
23-
prepare_host
24-
25-
# Run it twice and test for idempotency
26-
apply_manifest(pp, catch_failures: true)
27-
apply_manifest(pp, catch_changes: true)
25+
PUPPET
26+
end
2827
end
2928

3029
# do some basic checks
@@ -49,8 +48,7 @@ class { 'zabbix::database': }
4948
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
5049

5150
context "deploys a zabbix #{zabbix_version} server" do
52-
# Using puppet_apply as a helper
53-
it 'works idempotently with no errors' do
51+
it_behaves_like 'an idempotent resource' do
5452
# this is a minimal working example if you've a postgres server
5553
# running on another node. multinode testing with beaker is pain,
5654
# so we will deploy multiple services into one box
@@ -59,20 +57,15 @@ class { 'zabbix::database': }
5957
# manage_database => false,
6058
# }
6159
# EOS
62-
6360
# this will actually deploy apache + postgres + zabbix-server + zabbix-web
64-
pp = <<-EOS
61+
let(:manifest) do
62+
<<-PUPPET
6563
class { 'zabbix::database': }
6664
-> class { 'zabbix::server':
6765
zabbix_version => "#{zabbix_version}"
6866
}
69-
EOS
70-
71-
prepare_host
72-
73-
# Run it twice and test for idempotency
74-
apply_manifest(pp, catch_failures: true)
75-
apply_manifest(pp, catch_changes: true)
67+
PUPPET
68+
end
7669
end
7770

7871
# do some basic checks

spec/acceptance/zabbix_proxy_spec.rb

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,20 @@ class { 'zabbix':
4242
end
4343

4444
# setup proxies within zabbix
45-
pp2 = <<-EOS
46-
zabbix_proxy { 'ZabbixProxy1':
47-
mode => 0,
48-
}
49-
zabbix_proxy { 'ZabbixProxy2':
50-
ipaddress => '127.0.0.3',
51-
use_ip => false,
52-
mode => 1,
53-
port => 10055,
54-
}
55-
EOS
56-
57-
it 'works idempotently with no errors' do
58-
# Run it twice and test for idempotency
59-
apply_manifest(pp2, catch_failures: true)
60-
apply_manifest(pp2, catch_changes: true)
45+
it_behaves_like 'an idempotent resource' do
46+
let(:manifest) do
47+
<<-PUPPET
48+
zabbix_proxy { 'ZabbixProxy1':
49+
mode => 0,
50+
}
51+
zabbix_proxy { 'ZabbixProxy2':
52+
ipaddress => '127.0.0.3',
53+
use_ip => false,
54+
mode => 1,
55+
port => 10055,
56+
}
57+
PUPPET
58+
end
6159
end
6260

6361
let(:result_proxies) do
@@ -104,22 +102,20 @@ class { 'zabbix':
104102

105103
context 'update zabbix_proxy resources' do
106104
# This will update the Zabbix proxies created above by switching their configuration
107-
pp_update = <<-EOS
108-
zabbix_proxy { 'ZabbixProxy1':
109-
ipaddress => '127.0.0.3',
110-
use_ip => false,
111-
mode => 1,
112-
port => 10055,
113-
}
114-
zabbix_proxy { 'ZabbixProxy2':
115-
mode => 0,
116-
}
117-
EOS
118-
119-
it 'works idempotently with no errors' do
120-
# Run it twice and test for idempotency
121-
apply_manifest(pp_update, catch_failures: true)
122-
apply_manifest(pp_update, catch_changes: true)
105+
it_behaves_like 'an idempotent resource' do
106+
let(:manifest) do
107+
<<-PUPPET
108+
zabbix_proxy { 'ZabbixProxy1':
109+
ipaddress => '127.0.0.3',
110+
use_ip => false,
111+
mode => 1,
112+
port => 10055,
113+
}
114+
zabbix_proxy { 'ZabbixProxy2':
115+
mode => 0,
116+
}
117+
PUPPET
118+
end
123119
end
124120

125121
let(:result_proxies) do
@@ -166,19 +162,17 @@ class { 'zabbix':
166162

167163
context 'delete zabbix_proxy resources' do
168164
# This will delete the Zabbix proxies create above
169-
pp_delete = <<-EOS
170-
zabbix_proxy { 'ZabbixProxy1':
171-
ensure => absent,
172-
}
173-
zabbix_proxy { 'ZabbixProxy2':
174-
ensure => absent,
175-
}
176-
EOS
177-
178-
it 'works idempotently with no errors' do
179-
# Run it twice and test for idempotency
180-
apply_manifest(pp_delete, catch_failures: true)
181-
apply_manifest(pp_delete, catch_changes: true)
165+
it_behaves_like 'an idempotent resource' do
166+
let(:manifest) do
167+
<<-PUPPET
168+
zabbix_proxy { 'ZabbixProxy1':
169+
ensure => absent,
170+
}
171+
zabbix_proxy { 'ZabbixProxy2':
172+
ensure => absent,
173+
}
174+
PUPPET
175+
end
182176
end
183177

184178
let(:result_proxies) do

0 commit comments

Comments
 (0)