summaryrefslogtreecommitdiff
path: root/rdiff-backup/testing
diff options
context:
space:
mode:
authorben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-04-30 02:02:56 +0000
committerben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-04-30 02:02:56 +0000
commitd49f6dccf43983b317d31aa49b7e9a54aa28bf01 (patch)
tree1986d43b549551e12b60b6c03251061eae7bf433 /rdiff-backup/testing
parentef22311017db214255b24f93de2a43d75f9d45cc (diff)
downloadrdiff-backup-d49f6dccf43983b317d31aa49b7e9a54aa28bf01.tar.gz
Changed for 0.7.3 release
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@48 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/testing')
-rwxr-xr-xrdiff-backup/testing/chdir-wrapper9
-rw-r--r--rdiff-backup/testing/commontest.py34
-rw-r--r--rdiff-backup/testing/finaltest.py88
-rw-r--r--rdiff-backup/testing/incrementtest.py2
-rw-r--r--rdiff-backup/testing/regressiontest.py6
-rw-r--r--rdiff-backup/testing/restoretest.py59
-rw-r--r--rdiff-backup/testing/rorpitertest.py8
-rw-r--r--rdiff-backup/testing/selectiontest.py8
8 files changed, 180 insertions, 34 deletions
diff --git a/rdiff-backup/testing/chdir-wrapper b/rdiff-backup/testing/chdir-wrapper
index 413fcf2..073b297 100755
--- a/rdiff-backup/testing/chdir-wrapper
+++ b/rdiff-backup/testing/chdir-wrapper
@@ -7,9 +7,12 @@ the server. Otherwise will start the server without a chdir.
"""
-execfile("commontest.py")
-rbexec("setconnections.py")
+import os, sys
+
+#execfile("commontest.py")
+#rbexec("setconnections.py")
if len(sys.argv) > 1: os.chdir(sys.argv[1])
-PipeConnection(sys.stdin, sys.stdout).Server()
+#PipeConnection(sys.stdin, sys.stdout).Server()
+os.system("/home/ben/prog/python/rdiff-backup/src/rdiff-backup --server")
diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py
index 5728ad2..7ecf589 100644
--- a/rdiff-backup/testing/commontest.py
+++ b/rdiff-backup/testing/commontest.py
@@ -13,6 +13,10 @@ def rbexec(src_file):
execfile(src_file, globals())
os.chdir(AbsCurdir)
+def Myrm(dirstring):
+ """Run myrm on given directory string"""
+ assert not os.system("%s/myrm %s" % (MiscDir, dirstring))
+
def Make():
"""Make sure the rdiff-backup script in the source dir is up-to-date"""
os.chdir(SourceDir)
@@ -91,6 +95,7 @@ def InternalMirror(source_local, dest_local, src_dir, dest_dir,
rpin, rpout = SetConnections.InitRPs([src_dir, dest_dir], remote_schema)
_get_main().misc_setup([rpin, rpout])
+ _get_main().backup_init_select(rpin, rpout)
if not rpout.lstat(): rpout.mkdir()
if checkpointing: # rdiff-backup-data must exist to checkpoint
data_dir = rpout.append("rdiff-backup-data")
@@ -118,21 +123,20 @@ def InternalRestore(mirror_local, dest_local, mirror_dir, dest_dir, time):
mirror_rp, dest_rp = SetConnections.InitRPs([mirror_dir, dest_dir],
remote_schema)
-
- def get_increment_rp(time):
- """Return increment rp matching time"""
- data_rp = mirror_rp.append("rdiff-backup-data")
- for filename in data_rp.listdir():
- rp = data_rp.append(filename)
- if (rp.isincfile() and rp.getincbase_str() == "increments" and
- Time.stringtotime(rp.getinctime()) == time):
- return rp
- assert None, ("No increments.XXX.dir found in directory "
- "%s with that time" % data_rp.path)
-
- _get_main().Restore(get_increment_rp(time), dest_rp)
+ _get_main().Restore(get_increment_rp(mirror_rp, time), dest_rp)
_get_main().cleanup()
+def get_increment_rp(mirror_rp, time):
+ """Return increment rp matching time in seconds"""
+ data_rp = mirror_rp.append("rdiff-backup-data")
+ for filename in data_rp.listdir():
+ rp = data_rp.append(filename)
+ if (rp.isincfile() and rp.getincbase_str() == "increments" and
+ Time.stringtotime(rp.getinctime()) == time):
+ return rp
+ assert None, ("No increments.XXX.dir found in directory "
+ "%s with that time" % data_rp.path)
+
def _reset_connections(src_rp, dest_rp):
"""Reset some global connection information"""
Globals.isbackup_reader = Globals.isbackup_writer = None
@@ -148,7 +152,8 @@ def _get_main():
Globals.Main = Main()
return Globals.Main
-def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1):
+def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1,
+ equality_func = None):
"""Compare src_rp and dest_rp, which can be directories
This only compares file attributes, not the actual data. This
@@ -182,6 +187,7 @@ def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1):
dsiter1 = Hardlink.add_rorp_iter(dsiter1, 1)
dsiter2 = Hardlink.add_rorp_iter(dsiter2, None)
result = Iter.equal(dsiter1, dsiter2, 1, hardlink_equal)
+ elif equality_func: result = Iter.equal(dsiter1, dsiter2, 1, equality_func)
else: result = Iter.equal(dsiter1, dsiter2, 1)
for i in dsiter1: pass # make sure all files processed anyway
diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py
index a5ca5e1..c4c7cc6 100644
--- a/rdiff-backup/testing/finaltest.py
+++ b/rdiff-backup/testing/finaltest.py
@@ -65,12 +65,15 @@ class PathSetter(unittest.TestCase):
print "executing " + cmdstr
assert not os.system(cmdstr)
- def runtest(self):
- # Deleting previous output
+ def delete_tmpdirs(self):
+ """Remove any temp directories created by previous tests"""
assert not os.system(MiscDir + '/myrm testfiles/output* '
'testfiles/restoretarget* testfiles/vft_out '
'timbar.pyc')
+ def runtest(self):
+ self.delete_tmpdirs()
+
# Backing up increment1
self.exec_rb('testfiles/increment1', 'testfiles/output')
assert CompareRecursive(Local.inc1rp, Local.rpout)
@@ -147,4 +150,85 @@ class Final(PathSetter):
self.runtest()
+class FinalSelection(PathSetter):
+ """Test selection options"""
+ def testSelLocal(self):
+ """Quick backup testing a few selection options"""
+ self.delete_tmpdirs()
+
+ # Test --include option
+ assert not \
+ os.system(self.rb_schema +
+ "--current-time 10000 "
+ "--include testfiles/increment2/various_file_types "
+ "--exclude '**' "
+ "testfiles/increment2 testfiles/output")
+
+ assert os.lstat("testfiles/output/various_file_types/regular_file")
+ self.assertRaises(OSError, os.lstat, "testfiles/output/test.py")
+
+ # Now try reading list of files
+ fp = os.popen(self.rb_schema +
+ "--current-time 20000 "
+ "--include-filelist-stdin --exclude '**' "
+ "testfiles/increment2 testfiles/output", "w")
+ fp.write("""
+testfiles/increment2/test.py
+testfiles/increment2/changed_dir""")
+ assert not fp.close()
+
+ assert os.lstat("testfiles/output/changed_dir")
+ assert os.lstat("testfiles/output/test.py")
+ self.assertRaises(OSError, os.lstat,
+ "testfiles/output/various_file_types")
+ self.assertRaises(OSError, os.lstat,
+ "testfiles/output/changed_dir/foo")
+
+ # Test selective restoring
+ mirror_rp = RPath(Globals.local_connection, "testfiles/output")
+ restore_filename = get_increment_rp(mirror_rp, 10000).path
+ assert not os.system(self.rb_schema +
+ "--include testfiles/restoretarget1/various_file_types/"
+ "regular_file "
+ "--exclude '**' " +
+ restore_filename + " testfiles/restoretarget1")
+ assert os.lstat("testfiles/restoretarget1/various_file_types/"
+ "regular_file")
+ self.assertRaises(OSError, os.lstat, "testfiles/restoretarget1/tester")
+ self.assertRaises(OSError, os.lstat,
+ "testfiles/restoretarget1/various_file_types/executable")
+
+ fp = os.popen(self.rb_schema +
+ "--include-filelist-stdin " + restore_filename +
+ " testfiles/restoretarget2", "w")
+ fp.write("""
+- testfiles/restoretarget2/various_file_types/executable""")
+ assert not fp.close()
+ assert os.lstat("testfiles/restoretarget2/various_file_types/"
+ "regular_file")
+ self.assertRaises(OSError, os.lstat,
+ "testfiles/restoretarget2/various_file_types/executable")
+
+
+class FinalCorrupt(PathSetter):
+ def testBackupOverlay(self):
+ """Test backing up onto a directory already backed up for that time
+
+ This will test to see if rdiff-backup will ignore files who
+ already have an increment where it wants to put something.
+ Just make sure rdiff-backup doesn't exit with an error.
+
+ """
+ self.delete_tmpdirs()
+ assert not os.system("cp -a testfiles/corruptbackup testfiles/output")
+ self.set_connections(None, None, None, None)
+ self.exec_rb('testfiles/corruptbackup_source', 'testfiles/output')
+
+ def testBackupOverlayRemote(self):
+ """Like above but destination is remote"""
+ self.delete_tmpdirs()
+ assert not os.system("cp -a testfiles/corruptbackup testfiles/output")
+ self.set_connections(None, None, "test1/", '../')
+ self.exec_rb('testfiles/corruptbackup_source', 'testfiles/output')
+
if __name__ == "__main__": unittest.main()
diff --git a/rdiff-backup/testing/incrementtest.py b/rdiff-backup/testing/incrementtest.py
index 95c6b5b..e53e532 100644
--- a/rdiff-backup/testing/incrementtest.py
+++ b/rdiff-backup/testing/incrementtest.py
@@ -37,7 +37,7 @@ Globals.no_compression_regexp = \
class inctest(unittest.TestCase):
"""Test the incrementRP function"""
def setUp(self):
- pass
+ Globals.set('isbackup_writer',1)
def testreg(self):
"""Test increment of regular files"""
diff --git a/rdiff-backup/testing/regressiontest.py b/rdiff-backup/testing/regressiontest.py
index f9b2b4e..62f884d 100644
--- a/rdiff-backup/testing/regressiontest.py
+++ b/rdiff-backup/testing/regressiontest.py
@@ -192,21 +192,26 @@ class IncrementTest2(PathSetter):
"""After setting connections, etc., run actual test using this"""
Time.setcurtime()
SaveState.init_filenames(1)
+
+ _get_main().backup_init_select(Local.inc1rp, Local.rpout)
HighLevel.Mirror(self.inc1rp, self.rpout)
assert CompareRecursive(Local.inc1rp, Local.rpout)
Time.setcurtime()
Time.setprevtime(999500000)
+ _get_main().backup_init_select(self.inc2rp, self.rpout)
HighLevel.Mirror_and_increment(self.inc2rp, self.rpout, self.rpout_inc)
assert CompareRecursive(Local.inc2rp, Local.rpout)
Time.setcurtime()
Time.setprevtime(999510000)
+ _get_main().backup_init_select(self.inc3rp, self.rpout)
HighLevel.Mirror_and_increment(self.inc3rp, self.rpout, self.rpout_inc)
assert CompareRecursive(Local.inc3rp, Local.rpout)
Time.setcurtime()
Time.setprevtime(999520000)
+ _get_main().backup_init_select(self.inc4rp, self.rpout)
HighLevel.Mirror_and_increment(self.inc4rp, self.rpout, self.rpout_inc)
assert CompareRecursive(Local.inc4rp, Local.rpout)
@@ -415,6 +420,7 @@ class MirrorTest(PathSetter):
def Mirror(self, rpin, rpout, checkpoint = 1):
"""Like HighLevel.Mirror, but run misc_setup first"""
_get_main().misc_setup([rpin, rpout])
+ _get_main().backup_init_select(rpin, rpout)
HighLevel.Mirror(rpin, rpout, checkpoint)
if __name__ == "__main__": unittest.main()
diff --git a/rdiff-backup/testing/restoretest.py b/rdiff-backup/testing/restoretest.py
index 2db7dc6..597763d 100644
--- a/rdiff-backup/testing/restoretest.py
+++ b/rdiff-backup/testing/restoretest.py
@@ -1,7 +1,8 @@
import unittest
execfile("commontest.py")
-rbexec("restore.py")
+rbexec("main.py")
+Log.setverbosity(7)
lc = Globals.local_connection
@@ -26,12 +27,15 @@ class RestoreTest(unittest.TestCase):
rpbase = RPath(lc, self.prefix + basename)
rptarget = RPath(lc, "testfiles/outfile")
- if rptarget.lstat(): rptarget.delete()
for pair in tuples:
print "Processing file " + pair[0].path
+ if rptarget.lstat(): rptarget.delete()
rest_time = Time.stringtotime(pair[0].getinctime())
- Restore.RestoreFile(rest_time, rpbase, (), incs, rptarget)
+ sorted_incs = Restore.sortincseq(rest_time, incs)
+ Restore.RestoreFile(rest_time, rpbase, (), sorted_incs, rptarget)
+ rptarget.setdata()
if not rptarget.lstat(): assert not pair[1].lstat()
+ elif not pair[1].lstat(): assert not rptarget.lstat()
else:
assert RPath.cmp(rptarget, pair[1]), \
"%s %s" % (rptarget.path, pair[1].path)
@@ -39,9 +43,56 @@ class RestoreTest(unittest.TestCase):
"%s %s" % (rptarget.path, pair[1].path)
rptarget.delete()
+ def testsortincseq(self):
+ """Test the Restore.sortincseq function
+
+ This test just makes sure that it comes up with the right
+ number of increments for each base name - given a list of
+ increments, we should eventually get sorted sequences that
+ end in each one (each one will be the last increment once).
+
+ """
+ for basename in ['ocaml', 'mf']:
+ tuples, incs = self.maketesttuples(basename)
+ completed_dict = {}
+ for i in range(len(tuples)):
+ pair = tuples[i]
+ rest_time = Time.stringtotime(pair[0].getinctime())
+ sorted_incs = Restore.sortincseq(rest_time, incs)
+ key = sorted_incs[-1].path
+ assert not completed_dict.has_key(key)
+ completed_dict[key] = 1
+ for inc in incs: assert completed_dict[inc.path] == 1
+
+
def testRestorefiles(self):
"""Testing restoration of files one at a time"""
map(self.restoreonefiletest, ["ocaml", "mf"])
-
+
+ def testRestoreDir(self):
+ """Test restoring from a real backup set"""
+ Myrm("testfiles/output")
+ InternalRestore(1, 1, "testfiles/restoretest3",
+ "testfiles/output", 20000)
+
+ src_rp = RPath(Globals.local_connection, "testfiles/increment2")
+ restore_rp = RPath(Globals.local_connection, "testfiles/output")
+ assert CompareRecursive(src_rp, restore_rp)
+
+ def testRestoreCorrupt(self):
+ """Test restoring a partially corrupt archive
+
+ The problem here is that a directory is missing from what is
+ to be restored, but because the previous backup was aborted in
+ the middle, some of the files in that directory weren't marked
+ as .missing.
+
+ """
+ Myrm("testfiles/output")
+ InternalRestore(1, 1, "testfiles/restoretest4", "testfiles/output",
+ 10000)
+ assert os.lstat("testfiles/output")
+ self.assertRaises(OSError, os.lstat, "testfiles/output/tmp")
+ self.assertRaises(OSError, os.lstat, "testfiles/output/rdiff-backup")
if __name__ == "__main__": unittest.main()
diff --git a/rdiff-backup/testing/rorpitertest.py b/rdiff-backup/testing/rorpitertest.py
index 28ac54b..718f75a 100644
--- a/rdiff-backup/testing/rorpitertest.py
+++ b/rdiff-backup/testing/rorpitertest.py
@@ -70,17 +70,11 @@ class RORPIterTest(unittest.TestCase):
def compare_no_times(self, src_rp, dest_rp):
"""Compare but disregard directories attributes"""
- dsiter1, dsiter2 = map(DestructiveStepping.Iterate_with_Finalizer,
- [src_rp, dest_rp], [1, None])
-
def equal(src_rorp, dest_rorp):
return ((src_rorp.isdir() and dest_rorp.isdir()) or
src_rorp == dest_rorp)
- result = Iter.equal(dsiter1, dsiter2, 1, equal)
- for i in dsiter1: pass # make sure all files processed anyway
- for i in dsiter2: pass
- return result
+ return CompareRecursive(src_rp, dest_rp, None, equal)
class IndexedTupleTest(unittest.TestCase):
diff --git a/rdiff-backup/testing/selectiontest.py b/rdiff-backup/testing/selectiontest.py
index fc345d8..8b16193 100644
--- a/rdiff-backup/testing/selectiontest.py
+++ b/rdiff-backup/testing/selectiontest.py
@@ -79,7 +79,7 @@ class MatchingTest(unittest.TestCase):
testfiles/select/1/2
testfiles/select/1
testfiles/select/1/2/3
-testfiles/select/3/3/3""")
+testfiles/select/3/3/2""")
sf = self.Select.filelist_get_sf(fp, 1, "test")
assert sf(self.root) == 1
assert sf(self.makeext("1")) == 1
@@ -88,6 +88,7 @@ testfiles/select/3/3/3""")
assert sf(self.makeext("2/2")) == None
assert sf(self.makeext("3")) == 1
assert sf(self.makeext("3/3")) == 1
+ assert sf(self.makeext("3/3/3")) == None
def testFilelistExclude(self):
"""Test included filelist"""
@@ -95,7 +96,7 @@ testfiles/select/3/3/3""")
testfiles/select/1/2
testfiles/select/1
testfiles/select/1/2/3
-testfiles/select/3/3/3""")
+testfiles/select/3/3/2""")
sf = self.Select.filelist_get_sf(fp, 0, "test")
assert sf(self.root) == None
assert sf(self.makeext("1")) == 0
@@ -103,7 +104,8 @@ testfiles/select/3/3/3""")
assert sf(self.makeext("1/2/3")) == 0
assert sf(self.makeext("2/2")) == None
assert sf(self.makeext("3")) == None
- assert sf(self.makeext("3/3/3")) == 0
+ assert sf(self.makeext("3/3/2")) == 0
+ assert sf(self.makeext("3/3/3")) == None
def testFilelistInclude2(self):
"""testFilelistInclude2 - with modifiers"""