]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fuse/runtests: added write_partial_overwrite test
authorrobk-tahoe <robk-tahoe@allmydata.com>
Thu, 16 Oct 2008 14:29:26 +0000 (07:29 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Thu, 16 Oct 2008 14:29:26 +0000 (07:29 -0700)
this tests opening a file for update, overwriting a small part of it, and
ensuring that the end result constitutes an overwrite of the original file.
This tests, e.g. the implementation doesn' open a 'fresh' file but does in
fact initialise the file to be uploaded with the contents of any extant
file before applying updates

contrib/fuse/runtests.py

index c46d691373d154991475a15f52d61b8cecabbf8b..9f5591d6a8c63144fb5dfe45df7ff1a839e52107 100644 (file)
@@ -542,6 +542,49 @@ class SystemTest (object):
 
         self._check_write(testcap, name, body)
 
+    def test_write_partial_overwrite(self, testcap, testdir):
+        name = 'partial_overwrite'
+        body = '_'*132
+        overwrite = '^'*8
+        position = 26
+
+        def write_file(path, mode, contents, position=None):
+            try:
+                f = file(path, mode)
+                if position is not None:
+                    f.seek(position)
+                f.write(contents)
+                f.close()
+            except Exception, err:
+                tmpl = 'Could not write to file %r: %r'
+                raise TestFailure(tmpl, path, err)
+
+        def read_file(path):
+            try:
+                f = file(path, 'rb')
+                contents = f.read()
+                f.close()
+            except Exception, err:
+                tmpl = 'Could not read file %r: %r'
+                raise TestFailure(tmpl, path, err)
+            return contents
+
+        path = os.path.join(testdir, name)
+        #write_file(path, 'w', body)
+
+        cap = self.webapi_call('PUT', '/uri', body)
+        self.attach_node(testcap, cap, name)
+
+        contents = read_file(path)
+        if contents != body:
+            raise TestFailure('File contents mismatch (%r) %r v.s. %r', path, contents, body)
+
+        write_file(path, 'r+', overwrite, position)
+        contents = read_file(path)
+        expected = body[:position] + overwrite + body[position+len(overwrite):]
+        if contents != expected:
+            raise TestFailure('File contents mismatch (%r) %r v.s. %r', path, contents, expected)
+
 
     # Utilities:
     def run_tahoe(self, *args):