From 32afcf4af819aba1b9f8d94822dfb84152a0410b Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Wed, 6 Jan 2016 21:28:41 -0700 Subject: [PATCH] Add rspec-puppet-facts to the spec_helper This change adds the rspec-puppet-facts gem to the spec helper so that we can centralize the management of the base operating systems that we support. rspec-puppet-facts allows us to simplify our unit tests and provides a more complete list of Operating Systems and their associated facts for the unit tests. With this change we can now loop over and test CentOS, Debian, Fedora, RedHat, and Ubuntu by simply providing a list of supported os to rspec-puppet-facts. Additionally this change includes a central object for managing our supported os list for rspec-puppet-facts and providing our default facts like os_service_default. This central object should replace the usage of @default_facts within the unit tests for each module. Change-Id: I7eb1f4fdb413fa25a2560f65d17419efacf5c836 --- Gemfile | 1 + spec/defaults.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 8 +++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 spec/defaults.rb diff --git a/Gemfile b/Gemfile index fc22143..6d35d93 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" group :development, :test do gem 'puppetlabs_spec_helper', :require => 'false' gem 'rspec-puppet', '~> 2.2.0', :require => 'false' + gem 'rspec-puppet-facts', :require => 'false' gem 'metadata-json-lint', :require => 'false' gem 'puppet-lint-param-docs', :require => 'false' gem 'puppet-lint-absolute_classname-check', :require => 'false' diff --git a/spec/defaults.rb b/spec/defaults.rb new file mode 100644 index 0000000..548f3b2 --- /dev/null +++ b/spec/defaults.rb @@ -0,0 +1,44 @@ +# This file contains a module to return a default set of facts and supported +# operating systems for the tests in this module. +module OSDefaults + def self.get_facts(extra_facts={}) + { :os_service_default => '' }.merge(extra_facts) + end + + def self.get_supported_os + [ + { + "operatingsystem" => "CentOS", + "operatingsystemrelease" => [ + "7.0" + ] + }, + { + "operatingsystem" => "RedHat", + "operatingsystemrelease" => [ + "7.0" + ] + }, + { + "operatingsystem" => "Fedora", + "operatingsystemrelease" => [ + "21", + "22" + ] + }, + { + "operatingsystem" => "Ubuntu", + "operatingsystemrelease" => [ + "14.04" + ] + }, + { + "operatingsystem" => "Debian", + "operatingsystemrelease" => [ + "7", + "8" + ] + } + ] + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9bc7bcf..a2ccc7b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,11 +2,17 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'shared_examples' require 'webmock/rspec' +require 'rspec-puppet-facts' +include RspecPuppetFacts +require 'defaults.rb' + RSpec.configure do |c| c.alias_it_should_behave_like_to :it_configures, 'configures' c.alias_it_should_behave_like_to :it_raises, 'raises' + # TODO(aschultz): remove this after all tests converted to use OSDefaults + # instead of referencing @default_facts c.before :each do - @default_facts = { :os_service_default => '' } + @default_facts = OSDefaults.get_facts end end