def test_reader_partial(self): content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5('X').hexdigest() reader = vm_store._Reader(image) ret = reader.read(1) self.assertEqual('X', ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(1, reader.size)
def test_reader_full(self): content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() reader = vm_store._Reader(image) ret = reader.read() self.assertEqual(content, ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(len(content), reader.size)
def test_reader_partial(self): content = "XXX" image = six.StringIO(content) expected_checksum = hashlib.md5("X").hexdigest() reader = vm_store._Reader(image) ret = reader.read(1) self.assertEqual("X", ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(1, reader.size)
def test_reader_full(self): content = "XXX" image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() reader = vm_store._Reader(image) ret = reader.read() self.assertEqual(content, ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(len(content), reader.size)
def test_reader_size(self): """Test that the image reader takes into account the specified size.""" content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() checksum = hashlib.md5() reader = vm_store._Reader(image, checksum, blocksize=1) ret = reader.read(size=3) self.assertEqual('1\r\n', ret) ret = reader.read(size=1) self.assertEqual('X', ret) ret = reader.read() self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(image.len, reader.size) self.assertTrue(reader.closed)
def test_reader_image_larger_blocksize(self): """ Test that the image file reader returns the expected chunks when the block size specified is smaller than the image. """ content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() checksum = hashlib.md5() last_chunk = '0\r\n\r\n' reader = vm_store._Reader(image, checksum, blocksize=1) ret = reader.read() expected_chunk = '1\r\nX\r\n' self.assertEqual('%s%s%s%s' % (expected_chunk, expected_chunk, expected_chunk, last_chunk), ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(image.len, reader.size) self.assertTrue(reader.closed)
def test_reader_image_larger_blocksize(self): """ Test that the image file reader returns the expected chunks when the block size specified is smaller than the image. """ content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() checksum = hashlib.md5() last_chunk = '0\r\n\r\n' reader = vm_store._Reader(image, checksum, blocksize=1) ret = reader.read() expected_chunk = '1\r\nX\r\n' self.assertEqual( '%s%s%s%s' % (expected_chunk, expected_chunk, expected_chunk, last_chunk), ret) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(image.len, reader.size) self.assertTrue(reader.closed)
def test_reader_image_fits_in_blocksize(self): """ Test that the image file reader returns the expected chunk of data when the block size is larger than the image. """ content = 'XXX' image = six.StringIO(content) expected_checksum = hashlib.md5(content).hexdigest() checksum = hashlib.md5() reader = vm_store._Reader(image, checksum) ret = reader.read() expected_chunk = '%x\r\n%s\r\n' % (len(content), content) last_chunk = '0\r\n\r\n' self.assertEqual('%s%s' % (expected_chunk, last_chunk), ret) self.assertEqual(image.len, reader.size) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertTrue(reader.closed) ret = reader.read() self.assertEqual(image.len, reader.size) self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertTrue(reader.closed) self.assertEqual('', ret)