1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for repositories that support CHK indices."""
19
from bzrlib import osutils
20
from bzrlib.versionedfile import VersionedFiles
21
from bzrlib.tests.per_repository_chk import TestCaseWithRepositoryCHK
24
class TestCHKSupport(TestCaseWithRepositoryCHK):
26
def test_chk_bytes_attribute_is_VersionedFiles(self):
27
repo = self.make_repository('.')
28
self.assertIsInstance(repo.chk_bytes, VersionedFiles)
30
def test_add_bytes_to_chk_bytes_store(self):
31
repo = self.make_repository('.')
34
repo.start_write_group()
36
sha1, len, _ = repo.chk_bytes.add_lines((None,),
37
None, ["foo\n", "bar\n"], random_id=True)
38
self.assertEqual('4e48e2c9a3d2ca8a708cb0cc545700544efb5021',
41
set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
42
repo.chk_bytes.keys())
44
repo.abort_write_group()
47
repo.commit_write_group()
50
# And after an unlock/lock pair
54
set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
55
repo.chk_bytes.keys())
59
repo = repo.bzrdir.open_repository()
63
set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
64
repo.chk_bytes.keys())
68
def test_pack_preserves_chk_bytes_store(self):
69
leaf_lines = ["chkleaf:\n", "0\n", "1\n", "0\n", "\n"]
70
leaf_sha1 = osutils.sha_strings(leaf_lines)
71
node_lines = ["chknode:\n", "0\n", "1\n", "1\n", "foo\n",
72
"\x00sha1:%s\n" % (leaf_sha1,)]
73
node_sha1 = osutils.sha_strings(node_lines)
74
expected_set = set([('sha1:' + leaf_sha1,), ('sha1:' + node_sha1,)])
75
repo = self.make_repository('.')
78
repo.start_write_group()
80
# Internal node pointing at a leaf.
81
repo.chk_bytes.add_lines((None,), None, node_lines, random_id=True)
83
repo.abort_write_group()
86
repo.commit_write_group()
87
repo.start_write_group()
89
# Leaf in a separate pack.
90
repo.chk_bytes.add_lines((None,), None, leaf_lines, random_id=True)
92
repo.abort_write_group()
95
repo.commit_write_group()
97
self.assertEqual(expected_set, repo.chk_bytes.keys())
101
repo = repo.bzrdir.open_repository()
104
self.assertEqual(expected_set, repo.chk_bytes.keys())