summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/tc_byteback_snapshot.rb10
-rw-r--r--test/tc_restore.rb32
-rw-r--r--test/tc_restore_file.rb5
-rw-r--r--test/ts_byteback.rb7
4 files changed, 35 insertions, 19 deletions
diff --git a/test/tc_byteback_snapshot.rb b/test/tc_byteback_snapshot.rb
index 87b6409..71f8c39 100644
--- a/test/tc_byteback_snapshot.rb
+++ b/test/tc_byteback_snapshot.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/backup_directory'
require 'time'
@@ -58,7 +56,7 @@ class SnapshotTest < Test::Unit::TestCase
if biggest_offset.nil? or offsets.max > biggest_offset
biggest_offset = offsets.max
else
- puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
break
end
@@ -70,7 +68,7 @@ class SnapshotTest < Test::Unit::TestCase
end
#
- # This run the same test as above, execpt with 3 hosts all competeing for space
+ # This run the same test as above, execpt with 3 hosts all competing for space
#
def test_sort_by_importance_with_multiple_hosts
start = Time.now
@@ -106,7 +104,7 @@ class SnapshotTest < Test::Unit::TestCase
if biggest_offset.nil? or offsets.max > biggest_offset
biggest_offset = offsets.max
else
- puts "Oldest backup with space for #{limit} backups and 3 hosts is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups and 3 hosts is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
break
end
@@ -154,7 +152,7 @@ class SnapshotTest < Test::Unit::TestCase
day += 1
now += 86400
end
- puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
end
end
diff --git a/test/tc_restore.rb b/test/tc_restore.rb
index 426c2b1..03e98ad 100644
--- a/test/tc_restore.rb
+++ b/test/tc_restore.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/restore'
require 'tmpdir'
@@ -10,8 +8,6 @@ class RestoreTest < Test::Unit::TestCase
def setup
@byteback_root = Dir.mktmpdir
- @snapshot = Time.now.iso8601
- FileUtils.mkdir_p(File.join(@byteback_root, @snapshot))
end
def teardown
@@ -19,18 +15,36 @@ class RestoreTest < Test::Unit::TestCase
end
def test_find
+ create_snapshot_and_check_results(Time.now.iso8601.to_s)
+ end
+
+ def test_no_barf_on_non_timestamp_snapshot_name
+ create_snapshot_and_check_results("saved-hacked-do-not-delete")
+ end
+
+ def create_snapshot_and_check_results(snapshot)
+ FileUtils.mkdir_p(File.join(@byteback_root, snapshot))
files = %w(/srv/foo.com/public/htdocs/index.html
/srv/foo.com/public/htdocs/app.php)
files.each do |f|
- FileUtils.mkdir_p(File.join(@byteback_root, @snapshot, File.dirname(f)))
- FileUtils.touch(File.join(@byteback_root, @snapshot, f))
- system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, @snapshot, f)}")
+ FileUtils.mkdir_p(File.join(@byteback_root, snapshot, File.dirname(f)))
+ FileUtils.touch(File.join(@byteback_root, snapshot, f))
+ system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, snapshot, f)}")
+ assert_equal(0, $?.exitstatus)
end
r = Byteback::Restore.find(@byteback_root, "*", "/srv/foo.com/public/htdocs/*.html")
-
- r.list
+ assert(r.results.all?{|f| f.path =~ %r{/srv/foo.com/public/htdocs/.*.html}}, "Results returned did not match requested pattern")
+ assert(r.results.all?{|f| f.snapshot == snapshot}, "Results returned were not from the correct snapshot")
+
+ # Now check that we're getting the correct stuff from the rsync attr.
+ f = r.results.first
+ assert_equal(041755, f.mode, "Incorrect mode returned")
+ assert_equal(12, f.dev_major, "Incorrect dev_major returned")
+ assert_equal(34, f.dev_minor, "Incorrect dev_minor returned")
+ assert_equal(56, f.uid, "Incorrect UID returned")
+ assert_equal(78, f.gid, "Inocrrect GID returned")
end
end
diff --git a/test/tc_restore_file.rb b/test/tc_restore_file.rb
index e9544f9..8284275 100644
--- a/test/tc_restore_file.rb
+++ b/test/tc_restore_file.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/restore_file'
require 'tempfile'
@@ -20,8 +18,7 @@ class BytebackFileTest < Test::Unit::TestCase
end
def test_general
- f = Tempfile.new($0, @snapshot_path)
- puts f.path
+ f = Tempfile.new("restore-file-", @snapshot_path)
system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{f.path}")
b = Byteback::RestoreFile.new(f.path, @byteback_root)
assert_equal(041755, b.mode)
diff --git a/test/ts_byteback.rb b/test/ts_byteback.rb
new file mode 100644
index 0000000..ccee796
--- /dev/null
+++ b/test/ts_byteback.rb
@@ -0,0 +1,7 @@
+
+$: << File.dirname(__FILE__)
+$: << File.dirname(__FILE__)+"/../lib"
+
+require 'tc_restore.rb'
+require 'tc_restore_file.rb'
+require 'tc_byteback_snapshot.rb'