]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dump_uri_extension: improve test coverage of runner.py
authorBrian Warner <warner@lothar.com>
Tue, 26 Jun 2007 22:55:00 +0000 (15:55 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 26 Jun 2007 22:55:00 +0000 (15:55 -0700)
src/allmydata/scripts/runner.py
src/allmydata/test/test_system.py

index 2f0ac6a01b77b9acc726d50e7d1130511ff58761..b573dcc53fc1fc151030b822ed16ea9766fc2ae6 100644 (file)
@@ -325,7 +325,7 @@ def stop(basedir, config):
     print "never saw process go away"
     return 1
 
-def dump_uri_extension(config):
+def dump_uri_extension(config, output=sys.stdout):
     from allmydata import uri
 
     filename = config['filename']
@@ -338,23 +338,23 @@ def dump_uri_extension(config):
              "share_root_hash")
     for k in keys1:
         if k in unpacked:
-            print "%19s: %s" % (k, unpacked[k])
-    print
+            print >>output, "%19s: %s" % (k, unpacked[k])
+    print >>output
     for k in keys2:
         if k in unpacked:
-            print "%19s: %s" % (k, unpacked[k])
-    print
+            print >>output, "%19s: %s" % (k, unpacked[k])
+    print >>output
     for k in keys3:
         if k in unpacked:
-            print "%19s: %s" % (k, unpacked[k])
+            print >>output, "%19s: %s" % (k, unpacked[k])
 
     leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3)
     if leftover:
-        print
+        print >>output
         for k in sorted(leftover):
-            print "%s: %s" % (k, unpacked[k])
+            print >>output, "%s: %s" % (k, unpacked[k])
 
-    print
+    print >>output
     return 0
 
 def dump_root_dirnode(basedir, config, output=sys.stdout):
index af1bda46f9a27ff2b3d178044cb66dfd6db01263..509b7f46aec6edc5df4125a88d3f867b33cb073c 100644 (file)
@@ -1,11 +1,13 @@
 
 import os
+from cStringIO import StringIO
 from twisted.trial import unittest
 from twisted.internet import defer, reactor
 from twisted.application import service
 from allmydata import client, uri, download, upload
 from allmydata.introducer_and_vdrive import IntroducerAndVdrive
 from allmydata.util import idlib, fileutil, testutil
+from allmydata.scripts import runner
 from foolscap.eventual import flushEventualQueue
 from twisted.python import log
 from twisted.python.failure import Failure
@@ -259,6 +261,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
             self.failUnlessEqual(data, DATA)
         d.addCallback(_get_done)
         d.addCallback(self._test_web)
+        d.addCallback(self._test_runner)
         return d
     test_vdrive.timeout = 1100
 
@@ -360,3 +363,38 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
 
         return d
 
+    def _test_runner(self, res):
+        # exercise some of the diagnostic tools in runner.py
+
+        # find a uri_extension file
+        for (dirpath, dirnames, filenames) in os.walk(self.basedir):
+            if "uri_extension" in filenames:
+                break
+        else:
+            self.fail("unable to find any uri_extension files in %s"
+                      % self.basedir)
+        log.msg("test_system.SystemTest._test_runner using %s" % dirpath)
+
+        filename = os.path.join(dirpath, "uri_extension")
+        s = StringIO()
+        rc = runner.dump_uri_extension({'filename': filename}, s)
+        output = s.getvalue()
+        self.failUnlessEqual(rc, 0)
+
+        # we only upload a single file, so we can assert some things about
+        # its size and shares
+        self.failUnless("size: %d\n" % len(self.data) in output)
+        self.failUnless("num_segments: 1\n" in output)
+        # segment_size is always a multiple of needed_shares
+        self.failUnless("segment_size: 50\n" in output)
+        self.failUnless("total_shares: 100\n" in output)
+        # keys which are supposed to be present
+        for key in ("size", "num_segments", "segment_size",
+                    "needed_shares", "total_shares",
+                    "codec_name", "codec_params", "tail_codec_params",
+                    "plaintext_hash", "plaintext_root_hash",
+                    "crypttext_hash", "crypttext_root_hash",
+                    "share_root_hash",
+                    ):
+            self.failUnless("%s: " % key in output, key)
+