-
-
Save actionjack/a004df5b2eadd125c92014f83c988624 to your computer and use it in GitHub Desktop.
VHost ServerSpec Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################################################################### | |
# | |
# Purpose: beaker-rspec acceptance tests for Puppet Fundamentals lab "Apache Virtual Hosts" | |
# | |
# Usage: From the courseware directory: | |
# 1. 'bundle install' to install required gems | |
# 2. 'bundle exec rspec spec/acceptance/courses/fundamentals/Defined_Resources/Lab_ApacheVirtualHosts_spec.rb' to run the test | |
# | |
########################################################################################################################### | |
# Change the values below to test a different solution. | |
solution_name = 'Lab_ApacheVirtualHosts' | |
course_name = 'fundamentals' | |
module_name = 'apache' | |
lesson_name = 'defined_resources' | |
test_name = 'vhost.pp' | |
################################################################################################# | |
# | |
# DO NOT CHANGE THE FOLLOWING BLOCK | |
# | |
################################################################################################# | |
# Install the module and read the solution manifest | |
# Functions defined in spec/helper_functions.rb (included by spec_helper_acceptance) | |
install_solution_module(course_name, module_name) | |
solution_manifest = read_solution_manifest(course_name, module_name, test_name, lesson_name) | |
# Apply the solution manifest and verify that it runs cleanly. | |
# The "a solution manifest" shared example group is defined in | |
# spec/solution_manifest_spec.rb (included by spec_helper_acceptance) | |
# We pass the manifest under test to this group with the "let(:manifest) { solution_manifest }" declaration | |
describe "Solution #{solution_name} manifest", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do | |
it_behaves_like "a solution manifest" do | |
let(:manifest) { solution_manifest } | |
end | |
end | |
################################################################################################# | |
# | |
# LAB-SPECIFIC TESTS | |
# Change the tests below to verify the functionality of the module that you are testing | |
# | |
################################################################################################# | |
describe "Solution #{solution_name} results", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do | |
# Test 1: Ensure Apache Group Exists | |
describe group('apache') do | |
it { should exist } | |
end | |
# Test 2: Ensure Apache User Exists. | |
describe user('apache') do | |
it { should exist } | |
end | |
# Test 3: Ensure Docroot exists: | |
describe file('/var/www/html/myvhost.puppetlabs.vm') do | |
it { should exist } | |
it { should be_directory } | |
it { should be_owned_by 'apache' } | |
end | |
# Test 4: Ensure Index.html file exists for default vhost docroot | |
describe file('/var/www/html/myvhost.puppetlabs.vm/index.html') do | |
it { should exist } | |
it { should be_owned_by 'apache' } | |
end | |
# Test 5: Verify that the vhost has a hosts entry | |
describe host('myvhost.puppetlabs.vm') do | |
it { should be_resolvable.by('hosts')} | |
end | |
# Test 6: Verify that the vhost is listening on port 80 | |
describe port(80) do | |
it { should be_listening.with('tcp') } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment