diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-11-03 17:04:17 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-11-03 17:04:17 +0000 |
commit | 222fcd9945e127d15282cd628e2e956500783213 (patch) | |
tree | 66445709c4651f57956121e61b20f4ef4108cd6f | |
parent | f205ebeef227115021ee764458508ef3a139d1aa (diff) | |
download | morph-222fcd9945e127d15282cd628e2e956500783213.tar.gz |
Add tests for create_chunk's glob handling
-rw-r--r-- | morphlib/bins.py | 2 | ||||
-rw-r--r-- | morphlib/bins_tests.py | 33 |
2 files changed, 30 insertions, 5 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index 06956cd3..ed2ac555 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -27,7 +27,7 @@ import tarfile import morphlib -def create_chunk(rootdir, chunk_filename): +def create_chunk(rootdir, chunk_filename, globs): '''Create a chunk from the contents of a directory.''' logging.debug('Creating chunk file %s from %s' % (chunk_filename, rootdir)) tar = tarfile.open(name=chunk_filename, mode='w:gz') diff --git a/morphlib/bins_tests.py b/morphlib/bins_tests.py index 30076120..64858e7a 100644 --- a/morphlib/bins_tests.py +++ b/morphlib/bins_tests.py @@ -66,16 +66,41 @@ class ChunkTests(unittest.TestCase): def populate_instdir(self): os.mkdir(self.instdir) - os.mkdir(os.path.join(self.instdir, 'bin')) + + bindir = os.path.join(self.instdir, 'bin') + os.mkdir(bindir) + with open(os.path.join(bindir, 'foo'), 'w'): + pass + + libdir = os.path.join(self.instdir, 'lib') + os.mkdir(libdir) + with open(os.path.join(libdir, 'libfoo.so'), 'w'): + pass + + def test_empties_everything(self): + self.populate_instdir() + morphlib.bins.create_chunk(self.instdir, self.chunk_file, ['*']) + empty = os.path.join(self.tempdir, 'empty') + os.mkdir(empty) + self.assertEqual(recursive_lstat(self.instdir), empty) def test_creates_and_unpacks_chunk_exactly(self): self.populate_instdir() - morphlib.bins.create_chunk(self.instdir, self.chunk_file) + orig_files = recursive_lstat(self.instdir) + morphlib.bins.create_chunk(self.instdir, self.chunk_file, ['*']) os.mkdir(self.unpacked) morphlib.bins.unpack_chunk(self.chunk_file, self.unpacked) - self.assertEqual(recursive_lstat(self.instdir), - recursive_lstat(self.unpacked)) + self.assertEqual(orig_files, recursive_lstat(self.unpacked)) + def test_uses_only_matching_names(self): + self.populate_instdir() + morphlib.bins.create_chunk(self.instdir, self.chunk_file, ['bin/*']) + os.mkdir(self.unpacked) + morphlib.bins.unpack_chunk(self.chunk_file, self.unpacked) + self.assertEqual([x for x,y in recursive_lstat(self.unpacked)], + ['bin/foo']) + self.assertEqual([x for x,y in recursive_lstat(self.instdir)], + ['lib/libfoo.so']) class StratumTests(unittest.TestCase): |