1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009 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
237
236
self.assertEqual(("sha1:1234",), node.key())
238
237
self.assertEqual('pref\x00fo', node._search_prefix)
239
238
self.assertEqual({'pref\x00fo\x00': ('sha1:abcd',)}, node._items)
242
class Test_BytesToTextKey(tests.TestCase):
244
def assertBytesToTextKey(self, key, bytes):
245
self.assertEqual(key,
246
self.module._bytes_to_text_key(bytes))
248
def assertBytesToTextKeyRaises(self, bytes):
249
# These are invalid bytes, and we want to make sure the code under test
250
# raises an exception rather than segfaults, etc. We don't particularly
251
# care what exception.
252
self.assertRaises(Exception, self.module._bytes_to_text_key, bytes)
255
self.assertBytesToTextKey(('file-id', 'revision-id'),
256
'file: file-id\nparent-id\nname\nrevision-id\n'
257
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
259
def test_invalid_no_kind(self):
260
self.assertBytesToTextKeyRaises(
261
'file file-id\nparent-id\nname\nrevision-id\n'
262
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
264
def test_invalid_no_space(self):
265
self.assertBytesToTextKeyRaises(
266
'file:file-id\nparent-id\nname\nrevision-id\n'
267
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
269
def test_invalid_too_short_file_id(self):
270
self.assertBytesToTextKeyRaises('file:file-id')
272
def test_invalid_too_short_parent_id(self):
273
self.assertBytesToTextKeyRaises('file:file-id\nparent-id')
275
def test_invalid_too_short_name(self):
276
self.assertBytesToTextKeyRaises('file:file-id\nparent-id\nname')
279
self.assertBytesToTextKey(('dir-id', 'revision-id'),
280
'dir: dir-id\nparent-id\nname\nrevision-id')