3
require File.dirname(__FILE__) + '/../../lib/puppettest'
6
require 'puppettest/support/utils'
9
class TestFileBucket < Test::Unit::TestCase
10
include PuppetTest::Support::Utils
11
include PuppetTest::FileTesting
13
# this is complicated, because we store references to the created
14
# objects in a central store
17
assert_nothing_raised {
18
file = Puppet.type(:file).create(hash)
23
def mkbucket(name,path)
25
assert_nothing_raised {
26
bucket = Puppet.type(:filebucket).create(
38
# because luke's home directory is on nfs, it can't be used for testing
41
File.open(tmpfile, "w") { |f| f.puts rand(100) }
42
@@tmpfiles.push tmpfile
43
mkfile(:name => tmpfile)
51
system("rm -rf %s" % Puppet[:statefile])
56
Puppet::Util::Storage.init
57
Puppet::Util::Storage.load
61
Puppet::Util::Storage.store
62
Puppet::Util::Storage.clear
67
bucketpath = tempfile()
68
mkbucket(name, bucketpath)
71
assert_nothing_raised {
72
bucket = Puppet.type(:filebucket).bucket(name)
75
assert_instance_of(Puppet::Network::Client.dipper, bucket)
80
system("cp /etc/passwd %s" % newpath)
81
assert_nothing_raised {
82
md5 = bucket.backup(newpath)
87
dir, file, pathfile = Puppet::Network::Handler.filebucket.paths(bucketpath, md5)
89
assert(FileTest.directory?(dir),
90
"MD5 directory does not exist")
94
# Just in case the file isn't writable
95
File.chmod(0644, newpath)
96
File.open(newpath, "w") { |f| f.puts ";lkjasdf;lkjasdflkjwerlkj134lkj" }
98
assert_nothing_raised {
99
newmd5 = bucket.backup(newpath)
102
assert(md5 != newmd5)
104
assert_nothing_raised {
105
bucket.restore(newpath, md5)
108
File.open(newpath) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
110
assert_equal(md5, newmd5)
113
def test_fileswithbuckets
115
mkbucket(name, tempfile())
118
assert_nothing_raised {
119
bucket = Puppet.type(:filebucket).bucket(name)
123
assert_nothing_raised {
129
File.open(opath, "w") { |f| f.puts "yaytest" }
131
origmd5 = File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
133
file[:source] = opath
134
#assert_nothing_raised {
135
# file[:backup] = true
140
# so, we've now replaced the file with the opath file
142
File.open(opath) { |f| newmd5 = Digest::MD5.hexdigest(f.read) },
143
File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
146
#File.chmod(0644, file.name)
147
assert_nothing_raised {
148
bucket.restore(file.name, origmd5)
153
File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }