diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-24 21:16:20 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-24 21:16:20 +0000 |
| commit | 52df47e489d390be9b466da3ef16c2379b9dddba (patch) | |
| tree | d5006c428e3fae2646a6f60b5e7333dc2da31e87 /test | |
| parent | def15e3de0a488f2f9d75eeb43d04381742609f6 (diff) | |
Finalizing the filebucket client, with test code.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2348 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/executables/filebucket.rb | 49 | ||||
| -rwxr-xr-x | test/network/client/dipper.rb | 35 | ||||
| -rwxr-xr-x | test/network/handler/bucket.rb | 2 |
3 files changed, 85 insertions, 1 deletions
diff --git a/test/executables/filebucket.rb b/test/executables/filebucket.rb new file mode 100755 index 000000000..dbd5fed76 --- /dev/null +++ b/test/executables/filebucket.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppet' +require 'puppet/network/client' +require 'puppettest' +require 'socket' +require 'facter' + +class TestPBucket < Test::Unit::TestCase + include PuppetTest::ExeTest + + def test_local + bucket = tempfile + file = tempfile + text = "somet ext" + md5 = Digest::MD5.hexdigest(text) + File.open(file, "w") { |f| f.print text } + out = %x{pbucket --bucket #{bucket} backup #{file}} + + outfile, outmd5 = out.chomp.split(": ") + + assert_equal(0, $?, "pbucket did not run successfully") + + assert_equal(file, outfile, "did not output correct file name") + assert_equal(md5, outmd5, "did not output correct md5 sum") + + dipper = Puppet::Network::Client.dipper.new(:Path => bucket) + + newtext = nil + assert_nothing_raised("Could not get file from bucket") do + newtext = dipper.getfile(md5) + end + + assert_equal(text, newtext, "did not get correct file from md5 sum") + + out = %x{pbucket --bucket #{bucket} get #{md5}} + assert_equal(0, $?, "pbucket did not run successfully") + assert_equal(text, out, "did not get correct text back from pbucket") + + File.open(file, "w") { |f| f.puts "some other txt" } + out = %x{pbucket --bucket #{bucket} restore #{file} #{md5}} + assert_equal(0, $?, "pbucket did not run successfully") + assert_equal(text, File.read(file), "file was not restored") + end +end + +# $Id$ diff --git a/test/network/client/dipper.rb b/test/network/client/dipper.rb new file mode 100755 index 000000000..e91dea2a7 --- /dev/null +++ b/test/network/client/dipper.rb @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby + +$:.unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppet/network/client/resource' + +class TestDipperClient < Test::Unit::TestCase + include PuppetTest::ServerTest + + def setup + super + @dipper = Puppet::Network::Client.dipper.new(:Path => tempfile) + end + + # Make sure we can create a new file with 'restore'. + def test_restore_to_new_file + file = tempfile + text = "asdf;lkajseofiqwekj" + File.open(file, "w") { |f| f.puts text } + md5 = nil + assert_nothing_raised("Could not send file") do + md5 = @dipper.backup(file) + end + + newfile = tempfile + assert_nothing_raised("could not restore to new path") do + @dipper.restore(newfile, md5) + end + + assert_equal(File.read(file), File.read(newfile), "did not restore correctly") + end +end + +# $Id$ diff --git a/test/network/handler/bucket.rb b/test/network/handler/bucket.rb index 9c68afd29..eb488dd33 100755 --- a/test/network/handler/bucket.rb +++ b/test/network/handler/bucket.rb @@ -276,7 +276,7 @@ class TestBucket < Test::Unit::TestCase md5 = Digest::MD5.hexdigest(text) dirs = File.join(md5[0..7].split("")) - dir = File.join(@bucket, dirs) + dir = File.join(@bucket, dirs, md5) filedir, contents, paths = bucket.class.paths(@bucket, md5) assert_equal(dir, filedir, "did not use a deeper file structure") |
