Skip to content

Commit 250ee2c

Browse files
committed
test(inspec): add tests for package, config & service
1 parent 88ac182 commit 250ee2c

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
control 'ntp configuration' do
4+
title 'should match desired lines'
5+
6+
config_file = '/etc/ntp.conf'
7+
owner, group, mode =
8+
case platform[:family]
9+
when 'suse'
10+
%w[root ntp 0640]
11+
else
12+
%w[root root 0644]
13+
end
14+
15+
describe file(config_file) do
16+
it { should be_file }
17+
it { should be_owned_by owner }
18+
it { should be_grouped_into group }
19+
its('mode') { should cmp mode }
20+
its('content') { should include 'server 0.pool.ntp.org burst iburst' }
21+
its('content') { should include 'server 1.pool.ntp.org burst iburst' }
22+
its('content') { should include 'server 2.pool.ntp.org burst iburst' }
23+
its('content') { should include 'server 3.pool.ntp.org burst iburst' }
24+
its('content') { should include 'restrict 127.0.0.1' }
25+
its('content') { should include 'restrict ::1' }
26+
its('content') { should include 'driftfile /var/lib/ntp/ntp.drift' }
27+
end
28+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
control 'ntp package' do
4+
title 'should be installed'
5+
6+
pkg = 'ntp'
7+
8+
describe package(pkg) do
9+
it { should be_installed }
10+
end
11+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
service_name =
4+
case platform[:family]
5+
when 'debian'
6+
'ntp'
7+
else
8+
'ntpd'
9+
end
10+
11+
control 'ntp service' do
12+
impact 0.5
13+
title 'should be installed and enabled'
14+
15+
describe service(service_name) do
16+
it { should be_installed }
17+
it { should be_enabled }
18+
it { should be_running }
19+
end
20+
end

0 commit comments

Comments
 (0)