Skip to content

Commit

Permalink
🐛 fix wildcard values in labels
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Sep 28, 2023
1 parent 82b9629 commit d8843a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions engine/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ func matchesAny(elem string, items []string) bool {
// returns true when names of values are equal and the version of
// candidate falls within the version range of matchWith
func labelValueMatches(matchWith string, candidate string) bool {
// empty value treated as wildcard
if matchWith == "" {
return true
}
versionRegex := regexp.MustCompile(`(\d(?:[\d\.]*\d)?)([\+-])?$`)
mMatch := versionRegex.FindStringSubmatch(matchWith)
cMatch := versionRegex.FindStringSubmatch(candidate)
Expand Down
17 changes: 17 additions & 0 deletions engine/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,23 @@ func Test_ruleSelector_Matches(t *testing.T) {
},
want: true,
},
{
name: "simple wildcard value",
expr: "(konveyor.io/source=technology-usage)",
ruleLabels: []string{
"konveyor.io/source",
},
want: true,
},
{
name: "wildcard value expression",
expr: "(konveyor.io/target && konveyor.io/source=test)",
ruleLabels: []string{
"konveyor.io/target=eap",
"konveyor.io/source",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit d8843a5

Please sign in to comment.