From ee6997cd243f168b61b4ecf27026e8b2ecf8c68d Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 30 Sep 2014 17:15:02 -0700 Subject: [PATCH] (PDOC-9) Add preliminary full system test In order to help ensure that the strings module is not broken during development, add a full system integration test which can run at regular intervals to ensure that the module is working as expected. The test installs the string module as well as a test module which contains the different types of puppet and ruby code that the strings module can document. It then runs strings and ensures that the HTML generated is correct. Additionally, make some changes to the Gemfile to allow strings to be run as a gem even if it isn't installed in the modulepath. Also make a few changes to the unit tests to make them compatible with the version of rspec required by Beaker. --- .gitignore | 3 +++ Gemfile | 4 +++ Rakefile | 6 +++++ spec/acceptance/nodesets/default.yml | 13 ++++++++++ spec/acceptance/running_strings_yardoc.rb | 31 +++++++++++++++++++++++ spec/lib/strings_spec/parsing.rb | 10 ++++---- spec/spec_helper_acceptance.rb | 29 +++++++++++++++++++++ spec/unit/puppet/face_spec.rb | 2 +- 8 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/running_strings_yardoc.rb create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.gitignore b/.gitignore index 99e7d84..3369cc4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ Gemfile.lock ## YARD .yardoc + +## MODULE BUILDS +**/pkg diff --git a/Gemfile b/Gemfile index 96e5d5d..dfb1ad6 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' gem 'yard' gem 'rgen' gem 'redcarpet' +gem 'puppet-strings', '0.1.0', :path => '.' if puppetversion = ENV['PUPPET_VERSION'] gem 'puppet', puppetversion @@ -15,6 +16,9 @@ group :test do gem 'mocha' gem 'puppetlabs_spec_helper' gem 'rspec-html-matchers' + gem 'serverspec' + gem 'beaker' + gem 'beaker-rspec' end group :development do diff --git a/Rakefile b/Rakefile index d1e11f7..061eeb9 100644 --- a/Rakefile +++ b/Rakefile @@ -16,3 +16,9 @@ task :validate do sh "erb -P -x -T '-' #{template} | ruby -c" end end + +task :acceptance do + sh "puppet module build" + sh "puppet module build spec/unit/puppet/examples/test" + sh "rspec spec/acceptance/*.rb" +end diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..718f632 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,13 @@ +HOSTS: + master: + roles: + - master + platform: fedora-20-x86_64 + hypervisor: vcloud + template: Delivery/Quality Assurance/Templates/vCloud/fedora-20-x86_64 +CONFIG: + filecount: 12 + datastore: instance0 + resourcepool: delivery/Quality Assurance/FOSS/Dynamic + folder: Delivery/Quality Assurance/FOSS/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ diff --git a/spec/acceptance/running_strings_yardoc.rb b/spec/acceptance/running_strings_yardoc.rb new file mode 100644 index 0000000..7612ab4 --- /dev/null +++ b/spec/acceptance/running_strings_yardoc.rb @@ -0,0 +1,31 @@ +require 'spec_helper_acceptance' +require 'rspec-html-matchers' +require 'json' + +describe 'Genearting module documation using yardoc action' do + def read_file_on(host, filename) + on(host, "cat #{filename}").stdout + end + + before :all do + modules = JSON.parse(on(master, puppet("module", "list", "--render-as", "json")).stdout) + test_module_info = modules["modules_by_path"].values.flatten.find { |mod_info| mod_info =~ /Module test/ } + test_module_path = test_module_info.match(/\(([^)]*)\)/)[1] + + on master, puppet("strings", "#{test_module_path}/**/*.{rb,pp}") + end + + it "should generate documentation for manifests" do + expect(read_file_on(master, '/root/doc/test.html')).to have_tag('.docstring .discussion', :text => /This class/) + end + + it "should generate documenation for 3x functions" do + on master, 'cat /root/doc/Puppet3xFunctions.html' do + expect(read_file_on(master, '/root/doc/Puppet3xFunctions.html')).to have_tag('.docstring .discussion', :text => /documentation for `function3x`/) + end + end + + it "should generate documenation for 4x functions" do + expect(read_file_on(master, '/root/doc/Puppet4xFunctions.html')).to have_tag('.docstring .discussion', :text => /This is a function/) + end +end diff --git a/spec/lib/strings_spec/parsing.rb b/spec/lib/strings_spec/parsing.rb index 6dc2127..232bbfa 100644 --- a/spec/lib/strings_spec/parsing.rb +++ b/spec/lib/strings_spec/parsing.rb @@ -16,17 +16,17 @@ module StringsSpec # Registry is what we expect when testing handlers RSpec::Matchers.define :document_a do |arguments| match do |actual| - compare_values(actual).empty? + @mismatches = compare_values(actual, arguments) + @mismatches.empty? end - failure_message do |actual| - mismatches = compare_values(actual) - mismatches.collect do |key, value| + failure_message_for_should do + @mismatches.collect do |key, value| "Expected #{key} to be <#{value[1]}>, but got <#{value[0]}>." end.join("\n") end - def compare_values(actual) + def compare_values(actual, expected) mismatched_arguments = {} expected.each do |key, value| actual_value = actual.send(key) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..52f5d83 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,29 @@ +require 'beaker-rspec/spec_helper' +require 'beaker-rspec/helpers/serverspec' + +unless ENV['RS_PROVISION'] == 'no' + install_puppet +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + + hosts.each do |host| + scp_to(host, Dir.glob('pkg/puppetlabs-strings*.gz').first, 'strings.tar.gz') + on host, puppet('module', 'install', 'strings.tar.gz') + + scp_to(host, Dir.glob('spec/unit/puppet/examples/test/pkg/username-test*.gz').first, 'test.tar.gz') + on host, puppet('module', 'install', 'test.tar.gz') + + on host, 'gem install yard' + on host, 'gem install rgen' + end + end +end diff --git a/spec/unit/puppet/face_spec.rb b/spec/unit/puppet/face_spec.rb index 6cebb84..e8024ec 100644 --- a/spec/unit/puppet/face_spec.rb +++ b/spec/unit/puppet/face_spec.rb @@ -61,7 +61,7 @@ describe Puppet::Face do Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'test.html')).to have_tag('.docstring .discussion', :text => /This class/) + expect(read_html(tmp, 'test', 'Puppet4xFunctions.html')).to have_tag('.docstring .discussion', :text => /This is a function/) end end end