Skip to content

Commit f57af62

Browse files
Merge pull request #115 from carabasdaniel/main
Add pe_metric acceptance test and improve init spec test
2 parents 49a0274 + 3f7e1fe commit f57af62

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'hosts_with_pe_profile function' do
4+
it 'returns 127.0.0.1 when no hosts are found' do
5+
pp = <<-MANIFEST
6+
$result=puppet_metrics_collector::hosts_with_pe_profile('non_existant')
7+
notice "Received=$result"
8+
MANIFEST
9+
output = apply_manifest(pp).stdout
10+
expect(output).to match(%r{127.0.0.1})
11+
end
12+
it 'return the FQDN for the master profile' do
13+
# This influences the custom facts
14+
run_shell('puppet config set storeconfigs true --section user', expect_failures: false)
15+
pp = <<-MANIFEST
16+
$result=puppet_metrics_collector::hosts_with_pe_profile('master')
17+
notice "Received=$result"
18+
MANIFEST
19+
output = apply_manifest(pp).stdout
20+
expect(output).to match(host_inventory['fqdn'])
21+
run_shell('puppet config set storeconfigs false --section user', expect_failures: false)
22+
end
23+
end

spec/acceptance/init_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
MANIFEST
99

1010
# Run it twice and test for idempotency
11-
expect(apply_manifest(pp).exit_code).not_to eq(1)
12-
expect(apply_manifest(pp).exit_code).not_to eq(1)
1311
idempotent_apply(pp)
1412
end
1513
describe 'check systemd fact' do
1614
it 'is true on all supported OS' do
1715
expect(host_inventory['facter']['puppet_metrics_collector']['have_systemd']).to eq true
1816
end
1917
end
18+
describe 'check puppet-metrics-collector directory' do
19+
it 'scripts folder exists' do
20+
file('/opt/puppetlabs/puppet-metrics-collector/scripts').should be_directory
21+
end
22+
end
2023
end
2124
end

spec/acceptance/pe_metric_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'test default and system includes' do
4+
before(:all) do
5+
pp = <<-MANIFEST
6+
include puppet_metrics_collector
7+
include puppet_metrics_collector::system
8+
MANIFEST
9+
idempotent_apply(pp)
10+
end
11+
it 'sets all puppet_* metric services to be active' do
12+
run_shell('systemctl list-units --type=service | grep "puppet_.*metrics"') do |r|
13+
puts r.stdout
14+
expect(r.stdout).to match(%r{activ})
15+
end
16+
end
17+
it 'check for the tidy services files' do
18+
files = run_shell('ls /etc/systemd/system/puppet_*-tidy.service').stdout
19+
expect(files.split("\n").count).to eq(9)
20+
end
21+
it 'check for the timer files' do
22+
files = run_shell('ls /etc/systemd/system/puppet_*-tidy.timer').stdout
23+
expect(files.split("\n").count).to eq(9)
24+
end
25+
it 'checks if sysstat package is installed' do
26+
expect(package('sysstat')).to be_installed
27+
end
28+
end

0 commit comments

Comments
 (0)