Skip to content

Instantly share code, notes, and snippets.

@hunner
Last active May 17, 2018 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunner/fc630550d0cd8f2fe24a to your computer and use it in GitHub Desktop.
Save hunner/fc630550d0cd8f2fe24a to your computer and use it in GitHub Desktop.
Example code for beaker-rspec on master & agent
# This is what a test would look like.
require 'spec_helper_acceptance'
describe 'some class' do
it 'does stuff' do
pp=<<-EOS
notify { 'done stuff spec':
message => 'This message should appear',
}
EOS
make_site_pp(pp)
# First run for successful changes
run_agent({:acceptable_exit_codes => [0,2]})
# Second run for idempotency
run_agent({:acceptable_exit_codes => [0]})
end
#This is some code that can be placed in the spec/spec_helper_acceptance.rb
def make_sitepp(pp, path = File.join(master['puppetpath'], 'manifests'))
on master, "mkdir -p #{path}"
on master, create_remote_file(master, File.join(path, "site.pp"), pp)
on master, "chown -R #{master['user']}:#{master['group']} #{path}"
end
def run_agent(opts = {})
run_agent_on(default, opts)
end
def run_agent_on(hosts, opts = {})
exit_codes = Array(opts[:acceptable_exit_codes])
exit_codes |= [0]
shell(puppet('agent', '-t'), {:acceptable_exit_codes => exit_codes})
end
# And then the usual stuff...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment