summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-19 18:04:20 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-19 18:04:20 +0000
commit3891f48119ea01d04d7495cf2f07a9ddb37b2afc (patch)
tree564c02bc5cc3498a440ddea80e96a8852791c528 /test/lib
parentdcab464f8db80e6d8c91a595a77875222f2927bf (diff)
downloadpuppet-3891f48119ea01d04d7495cf2f07a9ddb37b2afc.tar.gz
puppet-3891f48119ea01d04d7495cf2f07a9ddb37b2afc.tar.xz
puppet-3891f48119ea01d04d7495cf2f07a9ddb37b2afc.zip
Converting to using the Rakefile for testing. The old 'test' script is
now deprecated, and I'll send an email to the dev list and update the docs to reflect that. This still isn't the final solution, because the module structure is a bit weird, but at least it's a starting point, and everything from here on out is small changes, as opposed to large architectural changes. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1632 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/puppettest.rb74
-rw-r--r--test/lib/puppettest/exetest.rb4
-rw-r--r--test/lib/puppettest/fakes.rb4
-rw-r--r--test/lib/puppettest/filetesting.rb (renamed from test/lib/puppettest/support/file.rb)7
-rw-r--r--test/lib/puppettest/parsertesting.rb (renamed from test/lib/puppettest/support/parser.rb)5
-rw-r--r--test/lib/puppettest/servertest.rb2
-rw-r--r--test/lib/puppettest/support.rb10
-rw-r--r--test/lib/puppettest/support/assertions.rb4
-rw-r--r--test/lib/puppettest/support/helpers.rb4
-rw-r--r--test/lib/puppettest/support/utils.rb16
10 files changed, 102 insertions, 28 deletions
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index b08cfcfd9..bff410060 100644
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -1,12 +1,54 @@
-require 'puppettest/support/helpers'
+require 'puppet'
+require 'test/unit'
module PuppetTest
- include PuppetTest::Support::Helpers
+ # Find the root of the Puppet tree; this is not the test directory, but
+ # the parent of that dir.
+ def basedir
+ unless defined? @@basedir
+ case $0
+ when /rake_test_loader/
+ @@basedir = File.dirname(Dir.getwd)
+ else
+ dir = nil
+ if /^#{File::SEPARATOR}.+\.rb/
+ dir = $0
+ else
+ dir = File.join(Dir.getwd, $0)
+ end
+ 3.times { dir = File.dirname(dir) }
+ @@basedir = dir
+ end
+ end
+ @@basedir
+ end
def cleanup(&block)
@@cleaners << block
end
+ def datadir
+ File.join(basedir, "test", "data")
+ end
+
+ def exampledir(*args)
+ unless defined? @@exampledir
+ @@exampledir = File.join(basedir, "examples")
+ end
+
+ if args.empty?
+ return @@exampledir
+ else
+ return File.join(@@exampledir, *args)
+ end
+ end
+
+ module_function :basedir, :datadir, :exampledir
+
+ def rake?
+ $0 =~ /rake_test_loader/
+ end
+
def setup
@memoryatstart = Puppet::Util.memory
if defined? @@testcount
@@ -38,16 +80,27 @@ module PuppetTest
@@cleaners = []
- if $0 =~ /.+\.rb/ or Puppet[:debug]
+ # If we're running under rake, then disable debugging and such.
+ if rake? and ! Puppet[:debug]
+ Puppet::Log.close
+ Puppet::Log.newdestination tempfile()
+ Puppet[:httplog] = tempfile()
+ else
Puppet::Log.newdestination :console
Puppet::Log.level = :debug
#$VERBOSE = 1
Puppet.info @method_name
- else
- Puppet::Log.close
- Puppet::Log.newdestination tempfile()
- Puppet[:httplog] = tempfile()
end
+ #if $0 =~ /.+\.rb/ or Puppet[:debug]
+ # Puppet::Log.newdestination :console
+ # Puppet::Log.level = :debug
+ # #$VERBOSE = 1
+ # Puppet.info @method_name
+ #else
+ # Puppet::Log.close
+ # Puppet::Log.newdestination tempfile()
+ # Puppet[:httplog] = tempfile()
+ #end
Puppet[:ignoreschedules] = true
end
@@ -136,4 +189,11 @@ module PuppetTest
end
end
+require 'puppettest/support'
+require 'puppettest/filetesting'
+require 'puppettest/fakes'
+require 'puppettest/exetest'
+require 'puppettest/parsertesting'
+require 'puppettest/servertest'
+
# $Id$
diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb
index 2d2a68db1..5f155b47f 100644
--- a/test/lib/puppettest/exetest.rb
+++ b/test/lib/puppettest/exetest.rb
@@ -1,4 +1,4 @@
-require 'servertest'
+require 'puppettest/servertest'
module PuppetTest::ExeTest
include PuppetTest::ServerTest
@@ -10,7 +10,7 @@ module PuppetTest::ExeTest
end
def bindir
- File.join($puppetbase, "bin")
+ File.join(basedir, "bin")
end
def setbindir
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index 42ba0c6af..0d27faf1f 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -1,4 +1,6 @@
-module PuppetTest::Fakes
+require 'puppettest'
+
+module PuppetTest
# A baseclass for the faketypes.
class FakeModel
class << self
diff --git a/test/lib/puppettest/support/file.rb b/test/lib/puppettest/filetesting.rb
index d2810d4e0..43a2ae1a0 100644
--- a/test/lib/puppettest/support/file.rb
+++ b/test/lib/puppettest/filetesting.rb
@@ -1,4 +1,7 @@
-module PuppetTest::Support::File
+require 'puppettest'
+
+module PuppetTest::FileTesting
+ include PuppetTest
def cycle(comp)
trans = nil
assert_nothing_raised {
@@ -221,7 +224,7 @@ module PuppetTest::Support::File
end
def conffile
- File.join($puppetbase,"examples/root/etc/configfile")
+ exampledir("root/etc/configfile")
end
end
diff --git a/test/lib/puppettest/support/parser.rb b/test/lib/puppettest/parsertesting.rb
index c4db871a5..e0606c501 100644
--- a/test/lib/puppettest/support/parser.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -1,4 +1,7 @@
-module PuppetTest::Support::Parser
+require 'puppettest'
+
+module PuppetTest::ParserTesting
+ include PuppetTest
AST = Puppet::Parser::AST
def astarray(*args)
diff --git a/test/lib/puppettest/servertest.rb b/test/lib/puppettest/servertest.rb
index 528b1a0d7..532256d74 100644
--- a/test/lib/puppettest/servertest.rb
+++ b/test/lib/puppettest/servertest.rb
@@ -1,4 +1,4 @@
-require 'scaffold'
+require 'puppettest'
module PuppetTest::ServerTest
include PuppetTest
diff --git a/test/lib/puppettest/support.rb b/test/lib/puppettest/support.rb
index 54b19ba7f..c81b5cd9d 100644
--- a/test/lib/puppettest/support.rb
+++ b/test/lib/puppettest/support.rb
@@ -1,8 +1,8 @@
+require 'puppettest'
+
module PuppetTest::Support
end
-require 'support/assertions'
-require 'support/file'
-require 'support/helpers'
-require 'support/parser'
-require 'support/utils'
+require 'puppettest/support/assertions'
+require 'puppettest/support/helpers'
+require 'puppettest/support/utils'
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 63ce0cccb..0e272002e 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -1,4 +1,6 @@
-module PuppetTest::Support::Assertions
+require 'puppettest'
+
+module PuppetTest
def assert_rollback_events(events, trans, msg = nil)
run_events(:rollback, events, trans, msg)
end
diff --git a/test/lib/puppettest/support/helpers.rb b/test/lib/puppettest/support/helpers.rb
index 41974d331..7fae994d9 100644
--- a/test/lib/puppettest/support/helpers.rb
+++ b/test/lib/puppettest/support/helpers.rb
@@ -1,4 +1,6 @@
-module PuppetTest::Support::Helpers
+require 'puppettest'
+
+module PuppetTest
def nonrootuser
Etc.passwd { |user|
if user.uid != Process.uid and user.uid > 0
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index 1b22e8d6e..00ea1a1c9 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -1,4 +1,6 @@
-module PuppetTest::Support::Utils
+require 'puppettest'
+
+module PuppetTest
def gcdebug(type)
Puppet.warning "%s: %s" % [type, ObjectSpace.each_object(type) { |o| }]
end
@@ -15,7 +17,7 @@ module PuppetTest::Support::Utils
assert_nothing_raised {
file = transport.to_type
}
- end
+ end
# stop any services that might be hanging around
def stopservices
@@ -24,7 +26,7 @@ module PuppetTest::Support::Utils
service[:ensure] = :stopped
service.evaluate
}
- end
+ end
end
# TODO: rewrite this to use the 'etc' module.
@@ -65,7 +67,7 @@ module PuppetTest::Support::Utils
# If there are any fake data files, retrieve them
def fakedata(dir)
- ary = [$puppetbase, "test"]
+ ary = [basedir, "test"]
ary += dir.split("/")
dir = File.join(ary)
@@ -80,7 +82,7 @@ module PuppetTest::Support::Utils
end
def fakefile(name)
- ary = [$puppetbase, "test"]
+ ary = [basedir, "test"]
ary += name.split("/")
file = File.join(ary)
unless FileTest.exists?(file)
@@ -100,7 +102,7 @@ module PuppetTest::Support::Utils
# a list of files that we can parse for testing
def textfiles
- textdir = File.join($puppetbase,"examples","code", "snippets")
+ textdir = File.join(exampledir,"code", "snippets")
Dir.entries(textdir).reject { |f|
f =~ /^\./ or f =~ /fail/
}.each { |f|
@@ -109,7 +111,7 @@ module PuppetTest::Support::Utils
end
def failers
- textdir = File.join($puppetbase,"examples","code", "failers")
+ textdir = File.join(exampledir,"code", "failers")
# only parse this one file now
files = Dir.entries(textdir).reject { |file|
file =~ %r{\.swp}