1
# Copyright (C) 2004, 2005, 2006, 2007, 2009 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
18
"""Tests for log+ transport decorator."""
24
from bzrlib.tests import TestCaseWithMemoryTransport
25
from bzrlib.trace import mutter
26
from bzrlib.transport import get_transport
27
from bzrlib.transport.log import TransportLogDecorator
30
class TestTransportLog(TestCaseWithMemoryTransport):
32
def test_log_transport(self):
33
base_transport = self.get_transport('')
34
logging_transport = get_transport('log+' + base_transport.base)
36
# operations such as mkdir are logged
37
mutter('where are you?')
38
logging_transport.mkdir('subdir')
39
self.assertContainsRe(self._get_log(True),
40
r'mkdir memory\+\d+://.*subdir')
41
self.assertContainsRe(self._get_log(True),
43
# they have the expected effect
44
self.assertTrue(logging_transport.has('subdir'))
45
# and they operate on the underlying transport
46
self.assertTrue(base_transport.has('subdir'))
48
def test_log_readv(self):
49
# see <https://bugs.launchpad.net/bzr/+bug/340347>
51
# transports are not required to return a generator, but we
52
# specifically want to check that those that do cause it to be passed
53
# through, for the sake of minimum interference
54
base_transport = DummyReadvTransport()
55
# construct it directly to avoid needing the dummy transport to be
57
logging_transport = TransportLogDecorator(
58
'log+dummy:///', _decorated=base_transport)
60
result = base_transport.readv('foo', [(0, 10)])
61
# sadly there's no types.IteratorType, and GeneratorType is too
63
self.assertTrue(getattr(result, 'next'))
65
result = logging_transport.readv('foo', [(0, 10)])
66
self.assertTrue(getattr(result, 'next'))
67
self.assertEquals(list(result),
71
class DummyReadvTransport(object):
75
def readv(self, filename, offset_length_pairs):
76
yield (0, 'abcdefghij')
78
def abspath(self, path):
79
return self.base + path