From b43893a59d868325ece91b252ee94fc7b8c8de0f Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Wed, 7 Feb 2024 13:33:24 -0500 Subject: [PATCH] :bug: respect match-all label values Signed-off-by: Pranav Gaikwad --- engine/labels/labels.go | 2 +- engine/labels/labels_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/engine/labels/labels.go b/engine/labels/labels.go index 8fa43c7a..00a95994 100644 --- a/engine/labels/labels.go +++ b/engine/labels/labels.go @@ -261,7 +261,7 @@ func tokenize(expr string) []string { func matchesAny(elem string, items []string) bool { for _, item := range items { - if labelValueMatches(item, elem) { + if item == "" || labelValueMatches(item, elem) { return true } } diff --git a/engine/labels/labels_test.go b/engine/labels/labels_test.go index 222f9aae..8034a8f5 100644 --- a/engine/labels/labels_test.go +++ b/engine/labels/labels_test.go @@ -386,6 +386,33 @@ func Test_ruleSelector_Matches(t *testing.T) { }, want: false, }, + { + name: "rule has a match-all source label", + expr: "konveyor.io/target=t1 && konveyor.io/source=t2", + ruleLabels: []string{ + "konveyor.io/target=t1", + "konveyor.io/source", + }, + want: true, + }, + { + name: "rule has a specific source label", + expr: "konveyor.io/target=t1 && konveyor.io/source=t2", + ruleLabels: []string{ + "konveyor.io/target=t1", + "konveyor.io/source=t3", + }, + want: false, + }, + { + name: "query contains match-all label", + expr: "konveyor.io/target=t1 && konveyor.io/source", + ruleLabels: []string{ + "konveyor.io/target=t1", + "konveyor.io/source=t3", + }, + want: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {