def test_mkfs_ext4(self):
with ExitStack() as resources:
tmpdir = resources.enter_context(TemporaryDirectory())
results_dir = os.path.join(tmpdir, 'results')
mock = MountMocker(results_dir)
resources.enter_context(
patch('ubuntu_image.helpers.run', mock.run))
# Create a temporary directory and populate it with some stuff.
contents_dir = resources.enter_context(TemporaryDirectory())
with open(os.path.join(contents_dir, 'a.dat'), 'wb') as fp:
fp.write(b'01234')
with open(os.path.join(contents_dir, 'b.dat'), 'wb') as fp:
fp.write(b'56789')
# And a fake image file.
img_file = resources.enter_context(NamedTemporaryFile())
mkfs_ext4(img_file, contents_dir)
# Two files were put in the "mountpoint" directory, but because of
# above, we have to check them in the results copy.
with open(os.path.join(mock.results_dir, 'a.dat'), 'rb') as fp:
self.assertEqual(fp.read(), b'01234')
with open(os.path.join(mock.results_dir, 'b.dat'), 'rb') as fp:
self.assertEqual(fp.read(), b'56789')
评论列表
文章目录