Skip to content

Commit 06e1452

Browse files
committed
test-label-analyzer: align filter expressions with review feedback
Signed-off-by: Avnish Jaltare <avnishjaltare8@gmail.com>
1 parent e06a617 commit 06e1452

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

robots/test-label-analyzer/cmd/filter/expressions.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"os"
25+
"regexp"
2526
"sort"
2627
"strings"
2728

@@ -41,7 +42,7 @@ var filterExpressionsOpts = &filterExpressionsOptions{}
4142
// JSON output as input and emitting filter expressions for both Ginkgo v1 text filters and
4243
// Ginkgo v2 label filters.
4344
var expressionsCmd = &cobra.Command{
44-
Use: "expressions",
45+
Use: "expressions <matching-tests.json>",
4546
Short: "Generates Ginkgo filter expressions from matching tests",
4647
Long: `Generates expressions that can be used with Ginkgo's --filter/--skip (v1) and --label-filter (v2) flags.
4748
@@ -145,23 +146,18 @@ func buildExpressions(matches matchingTests) expressionsOutput {
145146
if len(testNames) > 0 {
146147
parts := make([]string, 0, len(testNames))
147148
for _, name := range testNames {
148-
// Escape quotes inside names to keep expression simple.
149-
escaped := strings.ReplaceAll(name, `"`, `\"`)
150-
escaped = strings.ReplaceAll(escaped, `'`, `\'`)
151-
parts = append(parts, fmt.Sprintf("'%s'", escaped))
149+
parts = append(parts, regexp.QuoteMeta(name))
152150
}
153-
filterExpr = strings.Join(parts, " || ")
151+
filterExpr = strings.Join(parts, "|")
154152
}
155153

156154
var labelExpr string
157155
if len(reasons) > 0 {
158156
parts := make([]string, 0, len(reasons))
159157
for _, r := range reasons {
160-
escaped := strings.ReplaceAll(r, `"`, `\"`)
161-
escaped = strings.ReplaceAll(escaped, `'`, `\'`)
162-
parts = append(parts, fmt.Sprintf("'%s'", escaped))
158+
parts = append(parts, r)
163159
}
164-
labelExpr = strings.Join(parts, " || ")
160+
labelExpr = strings.Join(parts, "||")
165161
}
166162

167163
return expressionsOutput{

robots/test-label-analyzer/cmd/filter/expressions_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
package filter
2020

2121
import (
22-
"strings"
23-
2422
. "github.com/onsi/ginkgo/v2"
2523
. "github.com/onsi/gomega"
2624
)
@@ -38,13 +36,13 @@ var _ = Describe("expressions", func() {
3836
matches := matchingTests{
3937
{
4038
Id: "id-1",
41-
Reason: "Quarantine",
39+
Reason: "sig-network",
4240
Version: "",
4341
TestName: "test A",
4442
},
4543
{
4644
Id: "id-2",
47-
Reason: "Quarantine",
45+
Reason: "sig-storage",
4846
Version: "",
4947
TestName: "test B",
5048
},
@@ -53,13 +51,8 @@ var _ = Describe("expressions", func() {
5351
out := buildExpressions(matches)
5452

5553
Expect(out.Skip).To(BeEmpty())
56-
57-
// Filter should mention both test names
58-
Expect(out.Filter).To(ContainSubstring("test A"))
59-
Expect(out.Filter).To(ContainSubstring("test B"))
60-
61-
// LabelFilter should mention the reason once
62-
Expect(strings.Count(out.LabelFilter, "Quarantine")).To(Equal(1))
54+
Expect(out.Filter).To(Equal("test A|test B"))
55+
Expect(out.LabelFilter).To(Equal("sig-network||sig-storage"))
6356
})
6457
})
6558
})

0 commit comments

Comments
 (0)