From d8e00c37b574cfbfd60f91f5ffea89c31fcb625d Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Sat, 7 Feb 2009 15:14:40 -0700
Subject: [PATCH] test_cli.Backup: capture stderr when sqlite is unavailable

---
 src/allmydata/scripts/tahoe_backup.py |  2 +-
 src/allmydata/test/test_cli.py        | 15 +++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/allmydata/scripts/tahoe_backup.py b/src/allmydata/scripts/tahoe_backup.py
index 6d44ee69..c38dd455 100644
--- a/src/allmydata/scripts/tahoe_backup.py
+++ b/src/allmydata/scripts/tahoe_backup.py
@@ -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)
diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py
index 67e65a62..6bb855a7 100644
--- a/src/allmydata/test/test_cli.py
+++ b/src/allmydata/test/test_cli.py
@@ -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)
-- 
2.45.2