Refactor pieces of noop testing framework
This patch does the following: 1) Adds puppet_spec library to a list of fetched specs to leverage some of additional matchers 2) Makes spec_helper load puppet core spec directory which may also contain things we would want to reuse 3) Introduces new matcher for transitive dependencies that allows one to not search for exact dependencies with `that_comes_before` matcher, but to just check for resources dependencies Change-Id: Iad3b6f31a4c5be1ec306d9b4e7eedbd2cf720e95 Related-bug: #1533279
This commit is contained in:
parent
d0174c147a
commit
9af54824e7
1
Gemfile
1
Gemfile
|
@ -24,6 +24,7 @@ group :development, :test do
|
|||
gem 'beaker-rspec', :require => 'false'
|
||||
gem 'beaker-puppet_install_helper', :require => 'false'
|
||||
gem 'psych', :require => 'false'
|
||||
gem 'puppet-spec', :require => 'false'
|
||||
end
|
||||
|
||||
if puppetversion = ENV['PUPPET_GEM_VERSION']
|
||||
|
|
|
@ -10,6 +10,7 @@ group :development, :test do
|
|||
gem 'deep_merge'
|
||||
gem 'pry', :require => false
|
||||
gem 'simplecov', :require => false
|
||||
gem 'puppet-spec', :require => false
|
||||
end
|
||||
|
||||
if puppetversion = ENV['PUPPET_GEM_VERSION']
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
module FuelRelationshipGraphMatchers
|
||||
class EnsureTransitiveDependency
|
||||
def initialize(before, after)
|
||||
@before = before
|
||||
@after = after
|
||||
end
|
||||
|
||||
def matches?(actual_graph)
|
||||
@actual_graph = actual_graph
|
||||
|
||||
@dependents = actual_graph.dependents(
|
||||
vertex_called(actual_graph, @before))
|
||||
!@dependents.find_all { |d| d.ref =~ /#{Regexp.escape(@after)}/i }.empty?
|
||||
end
|
||||
|
||||
def failure_message
|
||||
msg = "expected deployment graph to contain a transitional dependency between\n"
|
||||
msg << "#{@before} and #{@after} but it did not happen\n"
|
||||
msg << "#{@before} dependents are: #{@dependents.map {|dep| dep.ref}}\n"
|
||||
msg
|
||||
end
|
||||
|
||||
def failure_message_when_negated
|
||||
msg = "expected deployment graph to NOT contain a transitional dependency between\n"
|
||||
msg << "#{@before} and #{@after} but it did not happen\n"
|
||||
msg << "#{@before} dependents are: #{@dependents.map {|dep| dep.ref}}\n"
|
||||
msg
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def vertex_called(graph, name)
|
||||
graph.vertices.find { |v| v.ref =~ /#{Regexp.escape(name)}/i }
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_transitive_dependency(before, after)
|
||||
EnsureTransitiveDependency.new(before, after)
|
||||
end
|
||||
end
|
|
@ -46,6 +46,24 @@ shared_examples 'save_files_list' do
|
|||
end
|
||||
|
||||
shared_examples 'OS' do
|
||||
include FuelRelationshipGraphMatchers
|
||||
|
||||
let (:catalog) do
|
||||
catalog = subject
|
||||
catalog = catalog.call if catalog.is_a? Proc
|
||||
end
|
||||
|
||||
let (:ral) do
|
||||
ral = catalog.to_ral
|
||||
ral.finalize
|
||||
ral
|
||||
end
|
||||
|
||||
let (:graph) do
|
||||
graph = Puppet::Graph::RelationshipGraph.new(Puppet::Graph::TitleHashPrioritizer.new)
|
||||
graph.populate_from(ral)
|
||||
graph
|
||||
end
|
||||
|
||||
include_examples 'compile'
|
||||
|
||||
|
|
|
@ -7,10 +7,13 @@ require 'puppetlabs_spec_helper/module_spec_helper'
|
|||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require 'find'
|
||||
#Load puppet spec additional libraries to use puppet internal matchers
|
||||
$LOAD_PATH << File.expand_path('../spec',Gem::Specification.find_by_name('puppet').lib_dirs_glob)
|
||||
require File.expand_path('../spec/spec_helper.rb',Gem::Specification.find_by_name('puppet').lib_dirs_glob)
|
||||
|
||||
class Noop
|
||||
lib_dir = File.expand_path File.absolute_path File.join File.dirname(__FILE__), 'lib'
|
||||
submodules = %w(catalog coverage debug facts files helpers overrides path spec tasks)
|
||||
submodules = %w(catalog coverage debug facts files helpers matchers overrides path spec tasks)
|
||||
|
||||
submodules.each do |submodule|
|
||||
require File.join lib_dir, submodule
|
||||
|
|
Loading…
Reference in New Issue