Ordering processing for volume ID substitutions

Related: https://pagure.io/pungi/issue/840

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
This commit is contained in:
Ondrej Nosek 2018-02-22 16:46:58 +01:00
parent 7ee920a085
commit caed78e11a
2 changed files with 25 additions and 1 deletions

View File

@ -322,7 +322,10 @@ def get_variant_data(conf, var_name, variant, keys=None):
def _apply_substitutions(compose, volid):
for k, v in compose.conf['volume_id_substitutions'].items():
substitutions = compose.conf['volume_id_substitutions'].items()
# processing should start with the longest pattern, otherwise, we could
# unexpectedly replace a substring of that longest pattern
for k, v in sorted(substitutions, reverse=True):
volid = volid.replace(k, v)
return volid

View File

@ -222,6 +222,27 @@ class TestVolumeIdGenerator(unittest.TestCase):
self.assertIn('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', str(ctx.exception))
self.assertIn('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', str(ctx.exception))
@mock.patch('pungi.compose.ComposeInfo')
def test_apply_substitutions(self, ci):
all_keys = [
('Fedora-WorkstationOstree-ostree-x86_64-rawhide', 'Fedora-WS-ostree-x86_64-rawhide'),
('Fedora-WorkstationOstree-ostree-x86_64-Rawhide', 'Fedora-WS-ostree-x86_64-rawh'),
('x86_64-compose_id-20160107', 'x86_64-compose_id-20160107'),
('x86_64-compose_id-20160107-Alpha', 'x86_64-compose_id-20160107-A'),
]
for volid, expected in all_keys:
conf = {
'volume_id_substitutions': {
'Rawhide': 'rawh',
'WorkstationOstree': 'WS',
'Workstation': 'WS',
'Alpha': 'A',
}
}
c = compose.Compose(conf, self.tmp_dir)
transformed_volid = util._apply_substitutions(c, volid)
self.assertEqual(transformed_volid, expected)
class TestFindOldCompose(unittest.TestCase):
def setUp(self):