summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorDominic Cleal <dcleal@redhat.com>2010-11-27 13:36:04 +0000
committerDominic Cleal <dcleal@redhat.com>2010-11-27 13:36:04 +0000
commitafe2d014feb2210a8666c93465d11e9c9d555f8b (patch)
tree208f5ac82b2c29610d2021821c8fca9b079e638b /test/lib
parent143fc744a839affd328234fca26246d49d15d3d8 (diff)
parent4b35402ba85d8842d757becec5c8a7bf4d6f6654 (diff)
Merge branch 'master' of github.com:domcleal/puppet into master-old
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/mocha_standalone.rb2
-rwxr-xr-xtest/lib/puppettest.rb30
-rw-r--r--test/lib/puppettest/fakes.rb2
-rw-r--r--test/lib/puppettest/parsertesting.rb13
-rw-r--r--test/lib/puppettest/support/assertions.rb2
-rw-r--r--test/lib/puppettest/support/utils.rb45
6 files changed, 36 insertions, 58 deletions
diff --git a/test/lib/mocha_standalone.rb b/test/lib/mocha_standalone.rb
deleted file mode 100644
index ce605811a..000000000
--- a/test/lib/mocha_standalone.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-require 'mocha/standalone'
-require 'mocha/object'
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index e31a31902..a60092cf7 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -6,17 +6,6 @@ mainlib = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
$LOAD_PATH.unshift(mainlib) unless $LOAD_PATH.include?(mainlib)
require 'puppet'
-
-# include any gems in vendor/gems
-Dir["#{mainlib}/../vendor/gems/**"].each do |path|
- libpath = File.join(path, "lib")
- if File.directory?(libpath)
- $LOAD_PATH.unshift(libpath)
- else
- $LOAD_PATH.unshift(path)
- end
-end
-
require 'mocha'
# Only load the test/unit class if we're not in the spec directory.
@@ -31,16 +20,7 @@ if ARGV.include?("-d")
$console = true
end
-# Some monkey-patching to allow us to test private methods.
-class Class
- def publicize_methods(*methods)
- saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods
-
- self.class_eval { public(*saved_private_instance_methods) }
- yield
- self.class_eval { private(*saved_private_instance_methods) }
- end
-end
+require File.expand_path(File.join(File.dirname(__FILE__), '../../spec/monkey_patches/publicize_methods'))
module PuppetTest
# These need to be here for when rspec tests use these
@@ -205,7 +185,7 @@ module PuppetTest
#if rake? or ! Puppet[:debug]
#if defined?($puppet_debug) or ! rake?
Puppet[:color] = false if textmate?
- Puppet::Util::Log.newdestination(@logs)
+ Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs))
if defined? $console
Puppet.info @method_name
Puppet::Util::Log.newdestination(:console)
@@ -227,14 +207,14 @@ module PuppetTest
#Facter.stubs(:to_hash).returns({})
end
- def tempfile
+ def tempfile(suffix = '')
if defined?(@@tmpfilenum)
@@tmpfilenum += 1
else
@@tmpfilenum = 1
end
- f = File.join(self.tmpdir, "tempfile_" + @@tmpfilenum.to_s)
+ f = File.join(self.tmpdir, "tempfile_" + @@tmpfilenum.to_s + suffix)
@@tmpfiles ||= []
@@tmpfiles << f
f
@@ -325,7 +305,7 @@ module PuppetTest
def logstore
@logs = []
- Puppet::Util::Log.newdestination(@logs)
+ Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs))
end
end
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index aaa711004..712332b74 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -1,4 +1,4 @@
-require 'puppettest'
+require File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/puppet/util'))
module PuppetTest
# A baseclass for the faketypes.
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index bd04c1ec5..411bad37a 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -94,16 +94,15 @@ module PuppetTest::ParserTesting
def resourcedef(type, title, params)
title = stringobj(title) unless title.is_a?(AST)
+ instance = AST::ResourceInstance.new(:title => title, :parameters => resourceparams(params))
assert_nothing_raised("Could not create #{type} #{title}") {
return AST::Resource.new(
:file => __FILE__,
:line => __LINE__,
- :title => title,
:type => type,
-
- :parameters => resourceinst(params)
+ :instances => AST::ASTArray.new(:children => [instance])
)
}
end
@@ -122,9 +121,7 @@ module PuppetTest::ParserTesting
:file => __FILE__,
:line => __LINE__,
:object => resourceref(type, title),
-
- :type => type,
- :parameters => resourceinst(params)
+ :parameters => resourceparams(params)
)
}
end
@@ -197,13 +194,13 @@ module PuppetTest::ParserTesting
}
end
- def resourceinst(hash)
+ def resourceparams(hash)
assert_nothing_raised("Could not create resource instance") {
params = hash.collect { |param, value|
resourceparam(param, value)
}
- return AST::ResourceInstance.new(
+ return AST::ASTArray.new(
:file => tempfile,
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 7f326b119..31fa3f1da 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -1,8 +1,6 @@
-require 'puppettest'
require 'puppettest/support/utils'
require 'fileutils'
-
module PuppetTest
include PuppetTest::Support::Utils
def assert_logged(level, regex, msg = nil)
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index edc81d3d6..e022f123c 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -1,5 +1,3 @@
-require 'puppettest'
-
module PuppetTest::Support
end
module PuppetTest::Support::Utils
@@ -7,6 +5,30 @@ module PuppetTest::Support::Utils
Puppet.warning "#{type}: #{ObjectSpace.each_object(type) { |o| }}"
end
+ def basedir(*list)
+ unless defined? @@basedir
+ Dir.chdir(File.dirname(__FILE__)) do
+ @@basedir = File.dirname(File.dirname(File.dirname(File.dirname(Dir.getwd))))
+ end
+ end
+ if list.empty?
+ @@basedir
+ else
+ File.join(@@basedir, *list)
+ end
+ end
+
+ def fakedata(dir,pat='*')
+ glob = "#{basedir}/test/#{dir}/#{pat}"
+ files = Dir.glob(glob,File::FNM_PATHNAME)
+ raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty?
+ files
+ end
+
+ def datadir(*list)
+ File.join(basedir, "test", "data", *list)
+ end
+
#
# TODO: I think this method needs to be renamed to something a little more
# explanatory.
@@ -38,10 +60,6 @@ module PuppetTest::Support::Utils
config
end
- # stop any services that might be hanging around
- def stopservices
- end
-
# TODO: rewrite this to use the 'etc' module.
# Define a variable that contains the name of my user.
@@ -84,7 +102,7 @@ module PuppetTest::Support::Utils
end
def fakefile(name)
- ary = [PuppetTest.basedir, "test"]
+ ary = [basedir, "test"]
ary += name.split("/")
file = File.join(ary)
raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file)
@@ -140,16 +158,3 @@ module PuppetTest::Support::Utils
config
end
end
-
-module PuppetTest
- include PuppetTest::Support::Utils
-
- def fakedata(dir,pat='*')
- glob = "#{basedir}/test/#{dir}/#{pat}"
- files = Dir.glob(glob,File::FNM_PATHNAME)
- raise Puppet::DevError, "No fakedata matching #{glob}" if files.empty?
- files
- end
- module_function :fakedata
-
-end