[util] Add function to search for old composes
This was already implemented as part of pkgset phase. It is now moved to the util module and covered with tests. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
f202d24961
commit
19c3707aee
4 changed files with 102 additions and 48 deletions
|
|
@ -13,6 +13,8 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|||
from pungi import compose
|
||||
from pungi import util
|
||||
|
||||
from tests.helpers import touch
|
||||
|
||||
|
||||
class TestGitRefResolver(unittest.TestCase):
|
||||
|
||||
|
|
@ -142,5 +144,54 @@ class TestVolumeIdGenerator(unittest.TestCase):
|
|||
self.assertEqual(volid, expected)
|
||||
|
||||
|
||||
class TestFindOldCompose(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp_dir = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
|
||||
def test_finds_single(self):
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'FINISHED')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.0')
|
||||
|
||||
def test_ignores_in_progress(self):
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'STARTED')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||
self.assertIsNone(old)
|
||||
|
||||
def test_finds_latest(self):
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS', 'DOOMED')
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0/STATUS', 'FINISHED')
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.1/STATUS', 'FINISHED_INCOMPLETE')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.1')
|
||||
|
||||
def test_finds_ignores_other_files(self):
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0', 'not a compose')
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS/file', 'also not a compose')
|
||||
touch(self.tmp_dir + '/Fedora-24-20160229.0/STATUS', 'FINISHED')
|
||||
touch(self.tmp_dir + '/Another-Rawhide-20160229.0/STATUS', 'FINISHED')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||
self.assertIsNone(old)
|
||||
|
||||
def test_search_in_file(self):
|
||||
touch(self.tmp_dir + '/file')
|
||||
old = util.find_old_compose(self.tmp_dir + '/file', 'Fedora', 'Rawhide')
|
||||
self.assertIsNone(old)
|
||||
|
||||
def test_skips_symlink(self):
|
||||
os.symlink(self.tmp_dir, self.tmp_dir + '/Fedora-Rawhide-20160229.0')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||
self.assertIsNone(old)
|
||||
|
||||
def test_finds_layered_product(self):
|
||||
touch(self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0/STATUS', 'FINISHED')
|
||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide',
|
||||
base_product_short='Base', base_product_version='1')
|
||||
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue