From 55b530f564f9c01550829763c179e320f305aaa0 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sun, 17 Jun 2018 11:33:36 -0400 Subject: [PATCH] Add rake test and rspec for aegir::hostmaster --- .fixtures.yml | 10 +++++ .gitignore | 1 + Rakefile | 23 ++++++++++++ spec/classes/hostmaster_spec.rb | 65 +++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 11 ++++++ 5 files changed, 110 insertions(+) create mode 100644 .fixtures.yml create mode 100644 .gitignore create mode 100644 Rakefile create mode 100644 spec/classes/hostmaster_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..74fa314 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,10 @@ +fixtures: + symlinks: + "aegir": "#{source_dir}" + forge_modules: + "apt": + repo: "puppetlabs/apt" + ref: "4.5.1" + "stdlib": + repo: "puppetlabs/stdlib" + ref: "4.16.0" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1db51fe --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +spec/fixtures diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..0a0f259 --- /dev/null +++ b/Rakefile @@ -0,0 +1,23 @@ +require 'puppetlabs_spec_helper/rake_tasks' + +defaults = [:validate, :spec] +begin + if Gem::Specification::find_by_name('metadata-json-lint') + defaults = defaults.insert(0, :metadata_lint) + end + if Gem::Specification::find_by_name('puppet-lint') + require 'puppet-lint/tasks/puppet-lint' + exclude_paths = [ + 'bundle/**/*', + 'pkg/**/*', + 'vendor/**/*', + 'spec/**/*' + ] + Rake::Task[:lint].clear + PuppetLint::RakeTask.new :lint do |config| + config.ignore_paths = exclude_paths + end + defaults = defaults.insert(-2, :lint) + end +end +task :test => defaults diff --git a/spec/classes/hostmaster_spec.rb b/spec/classes/hostmaster_spec.rb new file mode 100644 index 0000000..ff46f78 --- /dev/null +++ b/spec/classes/hostmaster_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' +describe 'aegir::hostmaster' do + let(:title) { 'aegir' } + let(:params) { + { 'database' => + { 'host' => 'localhost', + 'user' => 'aegir_root', + 'password' => 'password' }, + 'manage_sources' => false + } + } + # Need to fill out a fair amounts of facts for the apt module. + let(:facts) { + { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :os => { + 'name' => 'Debian', + 'lsb' => { + 'distcodename' => 'stretch' + }, + 'release' => { + 'full' => '', + 'major' => '9' + } + } + } + } + + it do + is_expected.to contain_file('/var/lib/dpkg/aegir.response') + is_expected.to contain_package('aegir').with( + 'ensure' => 'present', + 'name' => 'aegir3' + ) + end + + context 'with manage_sources => true' do + let(:params) { + { 'database' => + {'host' => 'localhost', + 'user' => 'aegir_root', + 'password' => 'password' }, + 'manage_sources' => true + } + } + it { is_expected.to contain_class('aegir::source') } + end + + context 'with server => nginx' do + let(:params) { + { 'database' => + { 'host' => 'localhost', + 'user' => 'aegir_root', + 'password' => 'password' }, + 'manage_sources' => false, + 'server' => 'nginx' + } + } + it do + is_expected.to contain_package('nginx').with_ensure('present') + is_expected.to contain_package('php7.0-fpm').with_ensure('present') + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b684e24 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,11 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet' + +fixture_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures') + +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + c.manifest = File.join(fixture_path, 'manifests', 'site.pp') + c.environmentpath = File.join(Dir.pwd, 'spec') +end