1
# Copyright (C) 2007, 2009-2012 Canonical Ltd
1
# Copyright (C) 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""Tests of the 'bzr pack' command."""
21
from bzrlib import tests
22
from bzrlib.tests.matchers import ContainsNoVfsCalls
25
class TestPack(tests.TestCaseWithTransport):
27
def _make_versioned_file(self, path, line_prefix='line', total_lines=10):
28
self._make_file(path, line_prefix, total_lines, versioned=True)
30
def _make_file(self, path, line_prefix, total_lines, versioned):
32
for i in range(total_lines):
33
text += line_prefix + str(i+1) + "\n"
35
with open(path, 'w') as f:
38
self.run_bzr(['add', path])
39
self.run_bzr(['ci', '-m', '"' + path + '"'])
41
def _update_file(self, path, text, checkin=True):
42
"""append text to file 'path' and check it in"""
43
with open(path, 'a') as f:
47
self.run_bzr(['ci', path, '-m', '"' + path + '"'])
20
from bzrlib.tests.blackbox import ExternalBase
23
class TestPack(ExternalBase):
49
25
def test_pack_silent(self):
50
26
"""pack command has no intrinsic output."""
51
27
self.make_branch('.')
66
42
out, err = self.run_bzr('pack repository')
67
43
self.assertEqual('', out)
68
44
self.assertEqual('', err)
70
def test_pack_clean_obsolete_packs(self):
71
"""Ensure --clean-obsolete-packs removes obsolete pack files
73
wt = self.make_branch_and_tree('.')
74
t = wt.branch.repository.bzrdir.transport
76
# do multiple commits to ensure that obsolete packs are created
78
self._make_versioned_file('file0.txt')
80
self._update_file('file0.txt', 'HELLO %d\n' % i)
82
out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
84
pack_names = t.list_dir('repository/obsolete_packs')
85
self.assertTrue(len(pack_names) == 0)
88
class TestSmartServerPack(tests.TestCaseWithTransport):
90
def test_simple_pack(self):
91
self.setup_smart_server_with_call_log()
92
t = self.make_branch_and_tree('branch')
93
self.build_tree_contents([('branch/foo', 'thecontents')])
96
self.reset_smart_call_log()
97
out, err = self.run_bzr(['pack', self.get_url('branch')])
98
# This figure represent the amount of HPSS calls to perform this use
99
# case. It is entirely ok to reduce this number if a test fails due to
100
# rpc_count # being too low. If rpc_count increases, more network
101
# roundtrips have become necessary for this use case. Please do not
102
# adjust this number upwards without agreement from bzr's network
103
# support maintainers.
104
self.assertLength(6, self.hpss_calls)
105
self.assertLength(1, self.hpss_connections)
106
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)