summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/bins.py2
-rw-r--r--morphlib/bins_tests.py33
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):