diff options
author | Lars Wirzenius <liw@xander> | 2010-12-26 13:49:39 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@xander> | 2010-12-26 13:49:39 +0200 |
commit | 91d67536018bffc12d352627a005bfb000b83394 (patch) | |
tree | 135acb7a8833414aba7441cc4b939f2ed1e8a148 | |
parent | 4abe4447a03b1ecaba3bd808a1c477ef0647578f (diff) | |
download | obnam-91d67536018bffc12d352627a005bfb000b83394.tar.gz |
Write tests for appending ids to a file's list of chunks.
-rw-r--r-- | obnamlib/clientmetadatatree.py | 3 | ||||
-rw-r--r-- | obnamlib/clientmetadatatree_tests.py | 26 | ||||
-rw-r--r-- | obnamlib/store.py | 10 | ||||
-rw-r--r-- | obnamlib/store_tests.py | 11 |
4 files changed, 50 insertions, 0 deletions
diff --git a/obnamlib/clientmetadatatree.py b/obnamlib/clientmetadatatree.py index e415545b..5c8c0370 100644 --- a/obnamlib/clientmetadatatree.py +++ b/obnamlib/clientmetadatatree.py @@ -311,6 +311,9 @@ class ClientMetadataTree(obnamlib.StoreTree): key = self.chunk_key(chunkid, file_id) self.tree.remove_range(key, key) + def append_file_chunks(self, filename, chunkids): + pass + def chunk_in_use(self, gen_id, chunk_id): '''Is a chunk used by a generation?''' diff --git a/obnamlib/clientmetadatatree_tests.py b/obnamlib/clientmetadatatree_tests.py index 8f7d990f..7eb6f366 100644 --- a/obnamlib/clientmetadatatree_tests.py +++ b/obnamlib/clientmetadatatree_tests.py @@ -232,6 +232,32 @@ class ClientMetadataTreeFileOpsTests(unittest.TestCase): self.client.set_file_chunks('/foo', [1, 2, 3]) self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), [1, 2, 3]) + + def test_appends_file_chunks_to_empty_list(self): + self.client.append_file_chunks('/foo', [1, 2, 3]) + self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), + [1, 2, 3]) + + def test_appends_file_chunks_to_nonempty_list(self): + self.client.set_file_chunks('/foo', [1, 2, 3]) + self.client.append_file_chunks('/foo', [4, 5, 6]) + self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), + [1, 2, 3, 4, 5, 6]) + + def test_generation_has_no_chunk_refs_initially(self): + minkey = self.client.chunk_key(0, 0) + maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID) + self.assertEqual(self.client.tree.lookup_range(minkey, maxkey), []) + + def test_generation_has_no_chunk_refs_initially(self): + minkey = self.client.chunk_key(0, 0) + maxkey = self.client.chunk_key(obnamlib.MAX_ID, obnamlib.MAX_ID) + self.assertEqual(self.client.tree.lookup_range(minkey, maxkey), []) + + def test_sets_file_chunks(self): + self.client.set_file_chunks('/foo', [1, 2, 3]) + self.assertEqual(self.client.get_file_chunks(self.clientid, '/foo'), + [1, 2, 3]) def test_generation_has_no_chunk_refs_initially(self): minkey = self.client.chunk_key(0, 0) diff --git a/obnamlib/store.py b/obnamlib/store.py index b9eb0a9f..6fd4a1ce 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -558,6 +558,16 @@ class Store(object): self.client.set_file_chunks(filename, chunkids) + @require_started_generation + def append_file_chunks(self, filename, chunkids): + '''Append to list of ids of chunks belonging to a file. + + File must be in the started generation. + + ''' + + self.client.append_file_chunks(filename, chunkids) + @require_open_client def genspec(self, spec): '''Interpret a generation specification.''' diff --git a/obnamlib/store_tests.py b/obnamlib/store_tests.py index 4128668d..a2e1fe9a 100644 --- a/obnamlib/store_tests.py +++ b/obnamlib/store_tests.py @@ -577,6 +577,17 @@ class StoreGetSetChunksTests(unittest.TestCase): chunkids = self.store.get_file_chunks(self.gen, '/foo') self.assertEqual(sorted(chunkids), [1, 2]) + def test_appends_chunks_to_empty_list(self): + self.store.append_file_chunks('/foo', [1, 2]) + chunkids = self.store.get_file_chunks(self.gen, '/foo') + self.assertEqual(sorted(chunkids), [1, 2]) + + def test_appends_chunks_to_nonempty_list(self): + self.store.append_file_chunks('/foo', [1, 2]) + self.store.append_file_chunks('/foo', [3, 4]) + chunkids = self.store.get_file_chunks(self.gen, '/foo') + self.assertEqual(sorted(chunkids), [1, 2, 3, 4]) + class StoreGenspecTests(unittest.TestCase): |