feat: try serverspec

DESCRIPTION
    Used local runner to perform the following tasks on my Arch Linux
    dev machine

    1. Check if apache is installed on arch
    2. Check if httpd service is enabled and running
    3. Check if port 80 is listening

COMMENTS
    Limited capabilities but seems to have support for basic testing
    on mulitple environments: local, SSH and Docker API  using multiple
    configuration management tools like Puppet and Ansible.

REFERENCES

[0]: https://serverspec.org/tutorial.html
[1]: https://serverspec.org/resource_types.html
This commit is contained in:
Aravinth Manivannan 2022-10-06 16:11:49 +05:30
parent d48a9f8e01
commit a24e814a1a
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
5 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,2 @@
--color
--format documentation

View File

@ -0,0 +1 @@
gem 'serverspec'

View File

@ -0,0 +1,27 @@
require 'rake'
require 'rspec/core/rake_task'
task :spec => 'spec:all'
task :default => :spec
namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end
task :all => targets
task :default => :all
targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end

View File

@ -0,0 +1,37 @@
require 'spec_helper'
describe package('apache'), if: os[:family] == 'arch' do
it { should be_installed }
end
describe service('httpd'), if: os[:family] == 'arch' do
it { should be_enabled }
it { should be_running }
end
describe package('httpd'), if: os[:family] == 'redhat' do
it { should be_installed }
end
describe package('apache2'), if: os[:family] == 'ubuntu' do
it { should be_installed }
end
describe service('httpd'), if: os[:family] == 'redhat' do
it { should be_enabled }
it { should be_running }
end
describe service('apache2'), if: os[:family] == 'ubuntu' do
it { should be_enabled }
it { should be_running }
end
describe service('org.apache.httpd'), if: os[:family] == 'darwin' do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end

View File

@ -0,0 +1,4 @@
require 'serverspec'
set :backend, :exec