From: robk-tahoe Date: Thu, 16 Oct 2008 14:29:26 +0000 (-0700) Subject: fuse/runtests: added write_partial_overwrite test X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/index.php?a=commitdiff_plain;h=85d1ec1c4436ef05969c8927ffeb2246899a2c13;p=tahoe-lafs%2Ftahoe-lafs.git fuse/runtests: added write_partial_overwrite test 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 --- diff --git a/contrib/fuse/runtests.py b/contrib/fuse/runtests.py index c46d6913..9f5591d6 100644 --- a/contrib/fuse/runtests.py +++ b/contrib/fuse/runtests.py @@ -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):