From 395efceea9dfc7aa8370a39078007e33d9ee7e01 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Wed, 19 Apr 2017 22:51:06 +0200 Subject: [PATCH] Add beaker test to module --- .gitignore | 1 + .travis.yml | 13 +++++-- Gemfile | 6 ++++ spec/acceptance/default_spec.rb | 53 ++++++++++++++++++++++++++++ spec/acceptance/nodesets/default.yml | 15 ++++++++ spec/spec_helper_acceptance.rb | 26 ++++++++++++++ 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 spec/acceptance/default_spec.rb create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.gitignore b/.gitignore index 9bf2add..36ad9d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Gemfile.lock pkg/ vendor/ +log/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5690ddc..8ee75ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,20 @@ sudo: false language: ruby cache: bundler -bundler_args: --without system_tests -script: "bundle exec rake validate && bundle exec rake spec SPEC_OPTS='--format documentation'" matrix: fast_finish: true include: - rvm: 2.1 + - rvm: 2.1 env: PUPPET_GEM_VERSION="~> 4.0" + script: "bundle exec rake validate" + - rvm: 2.1 + env: PUPPET_GEM_VERSION="~> 4.0" + script: "bundle exec rake spec SPEC_OPTS='--format documentation'" + - rvm: 2.1 + env: PUPPET_GEM_VERSION="~> 4.0" + script: "bundle exec rake beaker" + services: docker + sudo: required notifications: email: false diff --git a/Gemfile b/Gemfile index 8221837..ed19991 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,9 @@ gem 'puppetlabs_spec_helper', '>= 0.8.2' gem 'puppet-lint', '>= 1.0.0' gem 'facter', '>= 1.7.0' gem 'metadata-json-lint' + +group :acceptance do + gem 'beaker-rspec', '5.6.0' + gem 'serverspec', require: false + gem 'specinfra', require: false +end diff --git a/spec/acceptance/default_spec.rb b/spec/acceptance/default_spec.rb new file mode 100644 index 0000000..ecd4754 --- /dev/null +++ b/spec/acceptance/default_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper_acceptance' + +describe 'rsnapshot' do + context 'with defaults' do + it 'run idempotently' do + pp = <<-EOS + class { 'rsnapshot': + hosts => { + 'localhost' => {}, + 'example.com' => { + backup_defaults => false, + backup => { + '/var/' => './' + } + } + } + } + EOS + + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + end + + context 'packages installed' do + describe package('rsnapshot') do + it { is_expected.to be_installed } + end + end + context 'files provisioned' do + describe file('/etc/rsnapshot/localhost.rsnapshot.conf') do + it { is_expected.to exist } + its(:content) { is_expected.to match 'backup' } + end + describe file('/etc/rsnapshot/example.com.rsnapshot.conf') do + it { is_expected.to exist } + its(:content) { is_expected.to match 'backup' } + end + describe file('/etc/rsnapshot.conf') do + it { is_expected.to exist } + its(:content) { is_expected.to match 'localhost' } + its(:content) { is_expected.to match 'example.com' } + end + describe file('/etc/rsnapshot/localhost.rsnapshot.conf') do + it { is_expected.to exist } + its(:content) { is_expected.to match 'backup' } + end + describe file('/etc/cron.d/example_com') do + it { is_expected.to exist } + its(:content) { is_expected.to match 'example.com' } + end + end +end diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..70fbba8 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,15 @@ +HOSTS: + debian-8-x64: + platform: debian-8-amd64 + hypervisor: docker + image: debian:8 + docker_container_name: puppet_rsnapshot + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' + - 'rm -f /usr/sbin/policy-rc.d' +CONFIG: + trace_limit: 200 + masterless: true diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..8559254 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,26 @@ +require 'puppet' +require 'beaker-rspec' +require 'yaml' + +install_puppet_agent_on hosts, {} + +RSpec.configure do |c| + # Module root and settings + module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + module_name = module_root.split('/').last.sub('-', '_').split('_').last() + + c.formatter = :documentation + c.max_displayed_failure_line_count = 5 + + c.before :suite do + puts 'Install module' + puppet_module_install(source: module_root, module_name: module_name) + + hosts.each do |host| + puts 'Install fixtures' + on host, puppet('module','install','stahnma/epel') + on host, puppet('module','install','puppetlabs/stdlib') + on host, puppet('module','install','puppetlabs/concat') + end + end +end