From 451d76d1dd21b87a8fdd1b54a1655ad588e509e2 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 16 Oct 2019 23:35:33 +0100 Subject: [PATCH] test(inspec): add tests for package, config & service --- test/integration/default/controls/config.rb | 14 +++++++++++++ test/integration/default/controls/package.rb | 21 ++++++++++++++++++++ test/integration/default/controls/service.rb | 11 ++++++++++ 3 files changed, 46 insertions(+) create mode 100644 test/integration/default/controls/config.rb create mode 100644 test/integration/default/controls/package.rb create mode 100644 test/integration/default/controls/service.rb diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb new file mode 100644 index 00000000..dfd4d22d --- /dev/null +++ b/test/integration/default/controls/config.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +control 'Docker configuration' do + title 'should match desired lines' + + describe file('/etc/default/docker') do + it { should be_file } + its('owner') { should eq 'root' } + its('group') { should eq 'root' } + its('mode') { should cmp '0644' } + its('content') { should include 'DOCKER_OPTS="-s btrfs --dns 8.8.8.8"' } + its('content') { should include 'export http_proxy="http://172.17.42.1:3128"' } + end +end diff --git a/test/integration/default/controls/package.rb b/test/integration/default/controls/package.rb new file mode 100644 index 00000000..974981e4 --- /dev/null +++ b/test/integration/default/controls/package.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +control 'Docker package' do + title 'should be installed' + + package_name = + case platform[:family] + when 'debian' + 'docker-ce' + # Catch remaining `linux` platforms to identify by `name` at the end + when 'linux' + case platform[:name] + when 'arch' + 'docker' + end + end + + describe package(package_name) do + it { should be_installed } + end +end diff --git a/test/integration/default/controls/service.rb b/test/integration/default/controls/service.rb new file mode 100644 index 00000000..d5a83784 --- /dev/null +++ b/test/integration/default/controls/service.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +control 'Docker service' do + title 'should be running and enabled' + + describe service('docker') do + it { should be_installed } + it { should be_enabled } + it { should be_running } + end +end