summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-16 17:12:11 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-16 17:12:11 +0000
commita4562bfba94d18da54ad9560245d0669cc151c76 (patch)
treee923cb50e33737ba06ef6aefce373fbb9f3f97ff /test
parent42a9d9a3f8ac698370c36c4ca631e82797e01ece (diff)
downloadpuppet-a4562bfba94d18da54ad9560245d0669cc151c76.tar.gz
puppet-a4562bfba94d18da54ad9560245d0669cc151c76.tar.xz
puppet-a4562bfba94d18da54ad9560245d0669cc151c76.zip
Lots of refactoring, and added the capture_stderr method
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@742 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/other/storage.rb39
-rw-r--r--test/other/transactions.rb2
-rwxr-xr-xtest/puppet/utiltest.rb47
-rw-r--r--test/puppettest.rb11
-rwxr-xr-xtest/server/authstore.rb8
-rw-r--r--test/server/bucket.rb4
-rwxr-xr-xtest/server/fileserver.rb18
-rwxr-xr-xtest/test4
-rwxr-xr-xtest/types/component.rb9
-rwxr-xr-xtest/types/cron.rb3
-rwxr-xr-xtest/types/exec.rb2
-rw-r--r--test/types/fileignoresource.rb4
-rwxr-xr-xtest/types/group.rb2
-rw-r--r--test/types/package.rb2
-rw-r--r--test/types/query.rb12
-rw-r--r--test/types/service.rb5
-rwxr-xr-xtest/types/user.rb3
17 files changed, 117 insertions, 58 deletions
diff --git a/test/other/storage.rb b/test/other/storage.rb
new file mode 100755
index 000000000..aa010b7f3
--- /dev/null
+++ b/test/other/storage.rb
@@ -0,0 +1,39 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../.."
+end
+
+require 'puppet'
+require 'puppettest'
+require 'test/unit'
+
+class TestParsedFile < Test::Unit::TestCase
+ include TestPuppet
+
+ def test_storeandretrieve
+ hash = {:a => :b, :c => :d}
+
+ state = nil
+ assert_nothing_raised {
+ state = Puppet::Storage.state(hash)
+ }
+
+ assert(!state.include?("name"))
+
+ assert_nothing_raised {
+ state["name"] = hash
+ }
+
+ assert_nothing_raised {
+ Puppet::Storage.store
+ }
+ assert_nothing_raised {
+ state = Puppet::Storage.state(hash)
+ }
+
+ assert_equal(state["name"], hash)
+ end
+end
+
+# $Id$
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 738337dc4..c91c1456c 100644
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -25,12 +25,12 @@ class TestTransactions < Test::Unit::TestCase
end
def setup
+ super
@groups = %x{groups}.chomp.split(/ /)
unless @groups.length > 1
p @groups
raise "You must be a member of more than one group to test this"
end
- super
end
def teardown
diff --git a/test/puppet/utiltest.rb b/test/puppet/utiltest.rb
index 64eb07d17..e18971e59 100755
--- a/test/puppet/utiltest.rb
+++ b/test/puppet/utiltest.rb
@@ -8,13 +8,15 @@ require 'puppet'
require 'puppettest'
require 'test/unit'
-unless Process.uid == 0
- $stderr.puts "Run as root to perform Utility tests"
-else
class TestPuppetUtil < Test::Unit::TestCase
include TestPuppet
-
+ unless Process.uid == 0
+ $stderr.puts "Run as root to perform Utility tests"
+ else
def mknverify(file, user, group = nil, id = false)
+ if File.exists?(file)
+ File.unlink(file)
+ end
args = []
unless user or group
args << nil
@@ -60,15 +62,27 @@ class TestPuppetUtil < Test::Unit::TestCase
system("touch %s" % file)
}
}
- assert(File.exists?(file), "File does not exist")
- assert_equal(File.stat(file).uid, uid,
- "File is owned by %s instead of %s" %
- [File.stat(file).uid, uid]
- )
- assert_equal(File.stat(file).gid, gid,
- "File group is %s instead of %s" %
- [File.stat(file).gid, gid]
- )
+ if uid == 0
+ #Puppet.warning "Not testing user"
+ else
+ #Puppet.warning "Testing user %s" % uid
+ assert(File.exists?(file), "File does not exist")
+ assert_equal(File.stat(file).uid, uid,
+ "File is owned by %s instead of %s" %
+ [File.stat(file).uid, uid]
+ )
+ #system("ls -l %s" % file)
+ end
+ if gid == 0
+ #Puppet.warning "Not testing group"
+ else
+ #Puppet.warning "Testing group %s" % gid
+ assert_equal(File.stat(file).gid, gid,
+ "File group is %s instead of %s" %
+ [File.stat(file).gid, gid]
+ )
+ #system("ls -l %s" % file)
+ end
assert_nothing_raised {
File.unlink(file)
}
@@ -99,7 +113,12 @@ class TestPuppetUtil < Test::Unit::TestCase
assert(Process.euid == 0, "UID did not get reset")
end
-end
+ end
+
+ def test_capturestderr
+ str = Puppet::Util.capture_stderr { $stderr.puts("hello world") }
+ assert_equal("hello world\n", str)
+ end
end
# $Id$
diff --git a/test/puppettest.rb b/test/puppettest.rb
index f45356740..20bfb439d 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -34,7 +34,7 @@ module TestPuppet
Dir.mkdir(@configpath)
end
- @@tmpfiles = [@configpath]
+ @@tmpfiles = [@configpath, tmpdir()]
@@tmppids = []
if $0 =~ /.+\.rb/
@@ -128,6 +128,13 @@ module TestPuppet
else
"/tmp"
end
+
+ @tmpdir = File.join(@tmpdir, "puppettesting")
+
+ unless File.exists?(@tmpdir)
+ FileUtils.mkdir_p(@tmpdir)
+ File.chmod(01777, @tmpdir)
+ end
end
@tmpdir
end
@@ -303,7 +310,7 @@ module ExeTest
%x{#{ps}}.chomp.split(/\n/).each { |line|
if line =~ /ruby.+puppetmasterd/
next if line =~ /\.rb/ # skip the test script itself
- ary = line.split(/\s+/)
+ ary = line.sub(/^\s+/, '').split(/\s+/)
runningpid = ary[1].to_i
end
}
diff --git a/test/server/authstore.rb b/test/server/authstore.rb
index c7dfd0978..1875dee07 100755
--- a/test/server/authstore.rb
+++ b/test/server/authstore.rb
@@ -15,14 +15,6 @@ require 'puppettest.rb'
class TestAuthStore < Test::Unit::TestCase
include TestPuppet
- def setup
- if __FILE__ == $0
- Puppet[:loglevel] = :debug
- end
-
- super
- end
-
def mkstore
store = nil
assert_nothing_raised {
diff --git a/test/server/bucket.rb b/test/server/bucket.rb
index 5d45eedb2..ac418484e 100644
--- a/test/server/bucket.rb
+++ b/test/server/bucket.rb
@@ -21,8 +21,10 @@ class TestBucket < Test::Unit::TestCase
# iterate across all of the files
files.each { |file|
spin
+ tempdir = tempfile()
+ Dir.mkdir(tempdir)
name = File.basename(file)
- tmppath = File.join(tmpdir,name)
+ tmppath = File.join(tempdir,name)
@@tmpfiles << tmppath
# copy the files to our tmp directory so we can modify them...
diff --git a/test/server/fileserver.rb b/test/server/fileserver.rb
index 6712c30b7..f6037f17d 100755
--- a/test/server/fileserver.rb
+++ b/test/server/fileserver.rb
@@ -226,7 +226,7 @@ class TestFileServer < Test::Unit::TestCase
# verify we can mount /, which is what local file servers will
# normally do
- def test_mountroot
+ def test_zmountroot
server = nil
assert_nothing_raised {
server = Puppet::Server::FileServer.new(
@@ -247,6 +247,11 @@ class TestFileServer < Test::Unit::TestCase
}
assert(list =~ pattern)
+ assert_nothing_raised {
+ list = server.list("/root" + testdir, true, false)
+ }
+
+ assert(list =~ pattern)
end
# verify that we're correctly recursing the right number of levels
@@ -688,6 +693,17 @@ class TestFileServer < Test::Unit::TestCase
list = nil
end
+ # Verify that we get converted to the right kind of string
+ def test_mountstring
+ mount = nil
+ name = "yaytest"
+ path = tmpdir()
+ assert_nothing_raised {
+ mount = Puppet::Server::FileServer::Mount.new(name, path)
+ }
+
+ assert_equal(name + ":" + path, mount.to_s)
+ end
end
# $Id$
diff --git a/test/test b/test/test
index 15f9ad5f9..3f2bce2ae 100755
--- a/test/test
+++ b/test/test
@@ -6,6 +6,8 @@
$:.unshift '.'
$:.unshift '../lib'
+$puppetbase = ".."
+
require 'puppettest.rb'
require 'getoptlong'
@@ -26,8 +28,6 @@ result.each { |opt,arg|
end
}
-$puppetbase = ".."
-
suites = nil
if ARGV.length != 0
diff --git a/test/types/component.rb b/test/types/component.rb
index d52123ae0..ea1c797ac 100755
--- a/test/types/component.rb
+++ b/test/types/component.rb
@@ -13,15 +13,8 @@ require 'test/unit'
class TestComponent < Test::Unit::TestCase
include TestPuppet
def setup
- @@used = {}
- super
- end
-
- def teardown
- assert_nothing_raised() {
- Puppet::Type.allclear
- }
super
+ @@used = {}
end
def randnum(limit)
diff --git a/test/types/cron.rb b/test/types/cron.rb
index f26dd69ef..bcd5be93c 100755
--- a/test/types/cron.rb
+++ b/test/types/cron.rb
@@ -15,6 +15,7 @@ require 'facter'
class TestExec < Test::Unit::TestCase
include TestPuppet
def setup
+ super
# retrieve the user name
id = %x{id}.chomp
if id =~ /uid=\d+\(([^\)]+)\)/
@@ -27,8 +28,6 @@ class TestExec < Test::Unit::TestCase
end
# god i'm lazy
@crontype = Puppet::Type::Cron
-
- super
end
# Back up the user's existing cron tab if they have one.
diff --git a/test/types/exec.rb b/test/types/exec.rb
index 56b2439ad..bbe1ba3b6 100755
--- a/test/types/exec.rb
+++ b/test/types/exec.rb
@@ -220,6 +220,7 @@ class TestExec < Test::Unit::TestCase
}
if user
+ #Puppet.warning "Using user %s" % user.name
if id
# convert to a string, because that's what the object expects
args[:user] = user.uid.to_s
@@ -229,6 +230,7 @@ class TestExec < Test::Unit::TestCase
end
if group
+ #Puppet.warning "Using group %s" % group.name
if id
args[:group] = group.gid.to_s
else
diff --git a/test/types/fileignoresource.rb b/test/types/fileignoresource.rb
index f3d258381..ca89803d1 100644
--- a/test/types/fileignoresource.rb
+++ b/test/types/fileignoresource.rb
@@ -17,17 +17,17 @@ class TestFileIgnoreSources < Test::Unit::TestCase
include FileTesting
def setup
+ super
begin
initstorage
rescue
system("rm -rf %s" % Puppet[:checksumfile])
end
- super
end
def teardown
- clearstorage
super
+ clearstorage
end
#This is not needed unless using md5 (correct me if I'm wrong)
diff --git a/test/types/group.rb b/test/types/group.rb
index 68e7f08b8..215229063 100755
--- a/test/types/group.rb
+++ b/test/types/group.rb
@@ -14,8 +14,8 @@ require 'test/unit'
class TestGroup < Test::Unit::TestCase
include TestPuppet
def setup
- @@tmpgroups = []
super
+ @@tmpgroups = []
end
def teardown
diff --git a/test/types/package.rb b/test/types/package.rb
index 1936c8bbc..69fb16d5e 100644
--- a/test/types/package.rb
+++ b/test/types/package.rb
@@ -30,9 +30,9 @@ end
class TestPackages < Test::Unit::TestCase
include FileTesting
def setup
+ super
#@list = Puppet::Type::Package.getpkglist
Puppet::Type::Package.clear
- super
end
# These are packages that we're sure will be installed
diff --git a/test/types/query.rb b/test/types/query.rb
index 1793e1e17..86aadf678 100644
--- a/test/types/query.rb
+++ b/test/types/query.rb
@@ -5,21 +5,13 @@ if __FILE__ == $0
end
require 'puppet'
+require 'puppettest'
require 'test/unit'
# $Id$
class TestQuery < Test::Unit::TestCase
- def setup
- Puppet[:loglevel] = :debug if __FILE__ == $0
- end
-
- def teardown
- assert_nothing_raised() {
- Puppet::Type.allclear
- }
- end
-
+ include TestPuppet
# hmmm
# this is complicated, because we store references to the created
# objects in a central store
diff --git a/test/types/service.rb b/test/types/service.rb
index 5d99d662d..99384cf0b 100644
--- a/test/types/service.rb
+++ b/test/types/service.rb
@@ -14,16 +14,15 @@ class TestService < Test::Unit::TestCase
# this is complicated, because we store references to the created
# objects in a central store
def setup
+ super
sleeper = nil
script = File.join($puppetbase,"examples/root/etc/init.d/sleeper")
@status = script + " status"
-
- super
end
def teardown
- stopservices
super
+ stopservices
end
def mksleeper(hash = {})
diff --git a/test/types/user.rb b/test/types/user.rb
index 1869b3d08..4408cfa4b 100755
--- a/test/types/user.rb
+++ b/test/types/user.rb
@@ -14,9 +14,8 @@ require 'test/unit'
class TestUser < Test::Unit::TestCase
include TestPuppet
def setup
- @@tmpusers = []
- Puppet[:loglevel] = :debug if __FILE__ == $0
super
+ @@tmpusers = []
end
def teardown