From 9c22e17cef63718f90416889d4c7aca19150027b Mon Sep 17 00:00:00 2001 From: Glauco Oliveira Date: Fri, 11 Sep 2015 11:23:06 -0300 Subject: [PATCH] Add acceptance tests for puppet-httpd Add acceptance tests for puppet-httpd module so that once the module is applied we check if files were created, packages were installed and services were started. Change-Id: I3e1430f2937bd2bc5ea789c626784af7d5d85959 Co-Authored-By: Bruno Tavares Co-Authored-By: Danilo Ramalho --- .gitignore | 2 + Gemfile | 3 + spec/acceptance/basic_spec.rb | 116 ++++++++++++++++++++++++++++ spec/acceptance/fixtures/default.pp | 23 ++++++ 4 files changed, 144 insertions(+) create mode 100644 spec/acceptance/basic_spec.rb create mode 100644 spec/acceptance/fixtures/default.pp diff --git a/.gitignore b/.gitignore index a317ff1..850b086 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ Gemfile.lock .bundled_gems/ .pkg *.swp +.vagrant +log diff --git a/Gemfile b/Gemfile index 96912da..d69f807 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,10 @@ group :development, :test do else gem 'puppet', '~> 3.0', :require => false end +end +group :system_tests do + gem 'beaker-rspec', :require => false end # vim:ft=ruby diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb new file mode 100644 index 0000000..05a4176 --- /dev/null +++ b/spec/acceptance/basic_spec.rb @@ -0,0 +1,116 @@ +require 'spec_helper_acceptance' + +describe 'puppet-httpd module' do + def pp_path + base_path = File.dirname(__FILE__) + File.join(base_path, 'fixtures') + end + + def default_puppet_module + module_path = File.join(pp_path, 'default.pp') + File.read(module_path) + end + + it 'should work with no errors' do + apply_manifest(default_puppet_module, catch_failures: true) + end + + it 'should be idempotent', :if => ['debian', 'ubuntu'].include?(os[:family]) do + apply_manifest(default_puppet_module, catch_changes: true) + end + + it 'should be idempotent', :if => ['fedora', 'redhat'].include?(os[:family]) do + pending('this module is not idempotent on CentOS yet') + apply_manifest(default_puppet_module, catch_changes: true) + end + + describe 'required files' do + describe 'RedHat files', :if => ['fedora', 'redhat'].include?(os[:family]) do + describe file('/etc/httpd/conf.d/') do + it { should be_directory } + end + + describe file('/etc/httpd/conf.d/50-localhost.conf') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its(:content) { should include '' } + end + end + + describe 'Debian files', :if => ['debian', 'ubuntu'].include?(os[:family]) do + describe file('/etc/apache2/sites-enabled/') do + it { should be_directory } + end + + describe file('/etc/apache2/sites-enabled/50-localhost.conf') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its(:content) { should include '' } + end + + describe file('/etc/apache2/mods-enabled/python.load') do + it { should be_linked_to '../mods-available/python.load' } + end + + describe file('/etc/apache2/mods-enabled/ssl.load') do + it { should be_linked_to '../mods-available/ssl.load' } + end + + describe file('/etc/apache2/mods-enabled/rewrite.load') do + it { should be_linked_to '../mods-available/rewrite.load' } + end + end + end + + describe 'required packages' do + describe 'RedHat packages', :if => ['fedora', 'redhat'].include?(os[:family]) do + required_packages = [ + package('httpd'), + package('httpd-devel'), + package('php'), + package('mod_ssl'), + ] + + required_packages.each do |package| + describe package do + it { should be_installed } + end + end + end + + describe 'Debian packages', :if => ['debian', 'ubuntu'].include?(os[:family]) do + required_packages = [ + package('apache2'), + package('apache2-dev'), + package('libaprutil1-dev'), + package('libapr1-dev'), + package('libapache2-mod-php5'), + package('libapache2-mod-python'), + ] + + required_packages.each do |package| + describe package do + it { should be_installed } + end + end + end + end + + describe 'required services' do + describe service('httpd'), :if => ['fedora', 'redhat'].include?(os[:family]) do + it { should be_enabled } + it { should be_running } + end + + describe service('apache2'), :if => ['debian', 'ubuntu'].include?(os[:family]) do + it { should be_enabled } + it { should be_running } + end + + describe command('a2query -m ssl'), :if => ['debian', 'ubuntu'].include?(os[:family]) do + its(:stdout) { should match 'enabled' } + end + end +end diff --git a/spec/acceptance/fixtures/default.pp b/spec/acceptance/fixtures/default.pp new file mode 100644 index 0000000..9b3b7ec --- /dev/null +++ b/spec/acceptance/fixtures/default.pp @@ -0,0 +1,23 @@ +class { '::httpd': } +class { '::httpd::dev': } +class { '::httpd::php': } +class { '::httpd::mod::wsgi': } +class { '::httpd::ssl': } +httpd::vhost { 'localhost': + port => 80, + docroot => '/var/www', + priority => 50, + redirect_ssl => true, +} + +httpd::mod { 'rewrite': + ensure => present, +} + +case $::operatingsystem { + 'ubuntu', 'debian': { + class { '::httpd::python': } + } + default: {} +} +