summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-27 16:59:10 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-27 16:59:10 +0000
commit9b627cd0e061316feb73f332abb3c1e4e7aefe28 (patch)
tree72797181153ce9469fa06f382b3397b016be34c2 /test
parent003e897f6839b7f5e771c2b8f4c7feb9fadba4dc (diff)
downloadpuppet-9b627cd0e061316feb73f332abb3c1e4e7aefe28.tar.gz
Trying to track down the bugs reported this morning, so I added some more test cases. I did find a bug in the filebuckets, fixed it, and added a test case.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1143 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/types/file.rb39
-rwxr-xr-xtest/types/filebucket.rb6
-rwxr-xr-xtest/types/filesources.rb121
3 files changed, 77 insertions, 89 deletions
diff --git a/test/types/file.rb b/test/types/file.rb
index 28a12ab2f..04993db82 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -1077,6 +1077,45 @@ class TestFile < Test::Unit::TestCase
assert(FileTest.symlink?(link), "Did not make link")
assert_equal(File.join(source, "file"), File.readlink(link))
end
+
+ def test_backupmodes
+ file = tempfile()
+ newfile = tempfile()
+
+ File.open(file, "w", 0411) { |f| f.puts "yayness" }
+
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet::Type.type(:file).create(
+ :path => file, :content => "rahness\n"
+ )
+ }
+
+ assert_apply(obj)
+
+ backupfile = file + obj[:backup]
+ @@tmpfiles << backupfile
+ assert(FileTest.exists?(backupfile),
+ "Backup file %s does not exist" % backupfile)
+
+ assert_equal(0411, filemode(backupfile),
+ "File mode is wrong for backupfile")
+
+ bucket = "bucket"
+ bpath = tempfile()
+ Dir.mkdir(bpath)
+ Puppet::Type.type(:filebucket).create(
+ :name => bucket, :path => bpath
+ )
+
+ obj[:backup] = bucket
+ obj[:content] = "New content"
+ assert_apply(obj)
+
+ bucketedpath = File.join(bpath, "18cc17fa3047fcc691fdf49c0a7f539a", "contents")
+
+ assert_equal(0440, filemode(bucketedpath))
+ end
end
# $Id$
diff --git a/test/types/filebucket.rb b/test/types/filebucket.rb
index fa48c7d45..e7e7e3e73 100755
--- a/test/types/filebucket.rb
+++ b/test/types/filebucket.rb
@@ -68,7 +68,8 @@ class TestFileBucket < Test::Unit::TestCase
def test_simplebucket
name = "yayness"
- mkbucket(name, tempfile())
+ bucketpath = tempfile()
+ mkbucket(name, bucketpath)
bucket = nil
assert_nothing_raised {
@@ -87,6 +88,9 @@ class TestFileBucket < Test::Unit::TestCase
assert(md5)
+ assert(FileTest.directory?(File.join(bucketpath, md5)),
+ "MD5 directory does not exist")
+
newmd5 = nil
# Just in case the file isn't writable
diff --git a/test/types/filesources.rb b/test/types/filesources.rb
index c25081977..e4e59bb78 100755
--- a/test/types/filesources.rb
+++ b/test/types/filesources.rb
@@ -263,91 +263,6 @@ class TestFileSources < Test::Unit::TestCase
return file
end
- # test raw xmlrpc calls
- # this test is disabled because it requires way too much setup to get
- # the certificates correct
- def disabled_test_SimpleNetworkSources
- server = nil
- basedir = tempfile()
- @@tmpfiles << basedir
-
- mounts = {
- "/" => "root"
- }
-
- fileserverconf = mkfileserverconf(mounts)
-
- if File.exists?(basedir)
- system("rm -rf %s" % basedir)
- end
- Dir.mkdir(basedir)
-
- Puppet[:confdir] = basedir
- Puppet[:vardir] = basedir
- Puppet[:autosign] = true
-
- tmpname = "yaytesting"
- tmpfile = File.join(basedir, tmpname)
- File.open(tmpfile, "w") { |f| f.print rand(100) }
-
- port = 8765
- serverpid = nil
- assert_nothing_raised() {
- server = Puppet::Server.new(
- :Port => port,
- :Handlers => {
- :CA => {}, # so that certs autogenerate
- :FileServer => {
- :Config => fileserverconf
- }
- }
- )
-
- }
- serverpid = fork {
- assert_nothing_raised() {
- #trap(:INT) { server.shutdown; Kernel.exit! }
- trap(:INT) { server.shutdown }
- server.start
- }
- }
- @@tmppids << serverpid
-
- client = nil
- assert_nothing_raised() {
- client = XMLRPC::Client.new("localhost", "/RPC2", port, nil, nil,
- nil, nil, true, 3)
- }
- retval = nil
-
- sleep(1)
-
- list = nil
- rpath = "/root%s" % tmpfile
- assert_nothing_raised {
- list = client.call("fileserver.list", rpath, :skip, false, false)
- }
-
- assert_equal("/\tfile", list)
-
- assert_nothing_raised {
- list = client.call("fileserver.describe", rpath, :skip)
- }
-
- assert_match(/^\d+\tfile\t\d+\t\d+\t.+$/, list)
-
- assert_nothing_raised {
- list = client.call("fileserver.retrieve", rpath, :skip)
- }
-
- contents = File.read(tmpfile)
- assert_equal(contents, CGI.unescape(list))
-
- assert_nothing_raised {
- system("kill -INT %s" % serverpid)
- }
- end
-
def test_NetworkSources
server = nil
basedir = tempfile()
@@ -632,9 +547,39 @@ class TestFileSources < Test::Unit::TestCase
trans = comp.evaluate
trans.evaluate
}
- #assert(FileTest.symlink?(dest), "Destination is not a symlink")
- #assert_equal(File.readlink(link), File.readlink(dest),
- # "Link did not copy correctly")
+ end
+
+ def test_changes
+ source = tempfile()
+ dest = tempfile()
+
+ File.open(source, "w") { |f| f.puts "yay" }
+
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet.type(:file).create(
+ :name => dest,
+ :source => source
+ )
+ }
+
+ assert_events([:file_created], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
+
+ File.open(source, "w") { |f| f.puts "boo" }
+
+ assert_events([:file_changed], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
+
+ File.open(dest, "w") { |f| f.puts "kaboom" }
+
+ # There are two changes, because first the checksum is noticed, and
+ # then the source causes a change
+ assert_events([:file_changed, :file_changed], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
end
end