PR#1058: Add 'target' policy

Merges #1058
https://pagure.io/koji/pull-request/1058

Fixes: #1040
https://pagure.io/koji/issue/1040
rfe: target policy test
This commit is contained in:
Tomas Kopecek 2020-02-11 14:30:32 +01:00
commit 5ad52611c1
3 changed files with 24 additions and 0 deletions

View file

@ -204,6 +204,9 @@ Available tests
* for untag operations, tests the tag the build is being removed from
* only applicable to the tag policy
``target``
* matches against the build's target name. Accepts glob patterns.
``hastag``
* checks the current tags for the build in question against the arguments.

View file

@ -137,6 +137,18 @@ class MatchTest(BaseSimpleTest):
return False
class TargetTest(MatchTest):
"""Matches target in the data against glob patterns
True if any of the expressions match, else False
Syntax:
target pattern1 [pattern2 ...]
"""
name = 'target'
field = 'target'
class CompareTest(BaseSimpleTest):
"""Simple numeric field comparison

View file

@ -69,6 +69,14 @@ class TestBasicTests(unittest.TestCase):
self.assertTrue(obj.run({'thing': 'elseplus'}))
self.assertFalse(obj.run({}))
def test_target_test(self):
obj = koji.policy.TargetTest('target valid')
self.assertTrue(obj.run({'target': 'valid'}))
self.assertFalse(obj.run({'target': 'else'}))
obj = koji.policy.TargetTest('target valid else*')
self.assertTrue(obj.run({'target': 'valid'}))
self.assertTrue(obj.run({'target': 'elseplus'}))
def test_compare_test(self):
obj = koji.policy.CompareTest('compare thing > 2')
self.assertFalse(obj.run({'thing': 1}))
@ -120,6 +128,7 @@ class TestDiscovery(unittest.TestCase):
'has': koji.policy.HasTest,
'match': koji.policy.MatchTest,
'none': koji.policy.NoneTest,
'target': koji.policy.TargetTest,
'true': koji.policy.TrueTest,
}
self.assertDictEqual(expected, actual)