Skip to content

Commit

Permalink
test(inspec): add tests for package, config & service
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Oct 29, 2019
1 parent 88ac182 commit 250ee2c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

control 'ntp configuration' do
title 'should match desired lines'

config_file = '/etc/ntp.conf'
owner, group, mode =
case platform[:family]
when 'suse'
%w[root ntp 0640]
else
%w[root root 0644]
end

describe file(config_file) do
it { should be_file }
it { should be_owned_by owner }
it { should be_grouped_into group }
its('mode') { should cmp mode }
its('content') { should include 'server 0.pool.ntp.org burst iburst' }
its('content') { should include 'server 1.pool.ntp.org burst iburst' }
its('content') { should include 'server 2.pool.ntp.org burst iburst' }
its('content') { should include 'server 3.pool.ntp.org burst iburst' }
its('content') { should include 'restrict 127.0.0.1' }
its('content') { should include 'restrict ::1' }
its('content') { should include 'driftfile /var/lib/ntp/ntp.drift' }
end
end
11 changes: 11 additions & 0 deletions test/integration/default/controls/packages_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

control 'ntp package' do
title 'should be installed'

pkg = 'ntp'

describe package(pkg) do
it { should be_installed }
end
end
20 changes: 20 additions & 0 deletions test/integration/default/controls/services_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

service_name =
case platform[:family]
when 'debian'
'ntp'
else
'ntpd'
end

control 'ntp service' do
impact 0.5
title 'should be installed and enabled'

describe service(service_name) do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end

0 comments on commit 250ee2c

Please sign in to comment.