test_cli.Backup: capture stderr when sqlite is unavailable

This commit is contained in:
Brian Warner 2009-02-07 15:14:40 -07:00
parent 96774fba6b
commit d8e00c37b5
2 changed files with 12 additions and 5 deletions

View File

@ -144,7 +144,7 @@ class BackerUpper:
bdbfile = os.path.join(options["node-directory"],
"private", "backupdb.sqlite")
bdbfile = os.path.abspath(bdbfile)
self.backupdb = backupdb.get_backupdb(bdbfile)
self.backupdb = backupdb.get_backupdb(bdbfile, stderr)
rootcap, path = get_alias(options.aliases, options.to_dir, DEFAULT_ALIAS)
to_url = nodeurl + "uri/%s/" % urllib.quote(rootcap)

View File

@ -636,6 +636,13 @@ class Backup(SystemTestMixin, CLITestMixin, unittest.TestCase):
mo = re.search(r"(\d)+ files checked, (\d+) directories checked, (\d+) directories read", out)
return [int(s) for s in mo.groups()]
def nosqlite_is_ok(self, err, have_bdb):
if have_bdb:
self.failUnlessEqual(err, "")
else:
self.failUnlessEqual(err.strip(),
"sqlite unavailable, not using backupdb")
def test_backup(self):
self.basedir = os.path.dirname(self.mktemp())
@ -656,7 +663,7 @@ class Backup(SystemTestMixin, CLITestMixin, unittest.TestCase):
d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
d.addCallback(lambda res: self.do_cli("backup", source, "tahoe:backups"))
def _check0((rc, out, err)):
self.failUnlessEqual(err, "")
self.nosqlite_is_ok(err, have_bdb)
self.failUnlessEqual(rc, 0)
fu, fr, dc, dr = self.count_output(out)
# foo.txt, bar.txt, blah.txt
@ -704,7 +711,7 @@ class Backup(SystemTestMixin, CLITestMixin, unittest.TestCase):
def _check4a((rc, out, err)):
# second backup should reuse everything, if the backupdb is
# available
self.failUnlessEqual(err, "")
self.nosqlite_is_ok(err, have_bdb)
self.failUnlessEqual(rc, 0)
if have_bdb:
fu, fr, dc, dr = self.count_output(out)
@ -734,7 +741,7 @@ class Backup(SystemTestMixin, CLITestMixin, unittest.TestCase):
def _check4b((rc, out, err)):
# we should check all files, and re-use all of them. None of
# the directories should have been changed.
self.failUnlessEqual(err, "")
self.nosqlite_is_ok(err, have_bdb)
self.failUnlessEqual(rc, 0)
fu, fr, dc, dr = self.count_output(out)
fchecked, dchecked, dread = self.count_output2(out)
@ -780,7 +787,7 @@ class Backup(SystemTestMixin, CLITestMixin, unittest.TestCase):
def _check5a((rc, out, err)):
# second backup should reuse bar.txt (if backupdb is available),
# and upload the rest. None of the directories can be reused.
self.failUnlessEqual(err, "")
self.nosqlite_is_ok(err, have_bdb)
self.failUnlessEqual(rc, 0)
if have_bdb:
fu, fr, dc, dr = self.count_output(out)