Skip to content

Commit

Permalink
Fixed branch matcher pattern replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Jan 16, 2025
1 parent 97d9640 commit 4c08e2b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.48.3
appVersion: 1.68.3
version: 1.48.4
appVersion: 1.68.4
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/utils/branch/path_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
)

var (
patternReplacer = strings.NewReplacer("/**/", "/.*", "*", "[^/]*", "?", ".")
patternReplacer = strings.NewReplacer("/**/", "/.*", "*", ".*", "?", ".")
)

// IsValidPattern Checks that the path is a branch pattern
Expand Down
43 changes: 37 additions & 6 deletions pkg/apis/utils/branch/path_matcher_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package branch

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -23,18 +24,44 @@ func TestIsValidPattern(t *testing.T) {
assert.True(t, IsValidPattern("??st"))
assert.True(t, IsValidPattern("?est/*"))
assert.True(t, IsValidPattern("te?t/*"))
assert.True(t, IsValidPattern("*"))
assert.True(t, IsValidPattern("**"))
assert.True(t, IsValidPattern(".*"))
assert.True(t, IsValidPattern(".*/*"))
assert.True(t, IsValidPattern(".**"))
assert.True(t, IsValidPattern("test-test"))
assert.True(t, IsValidPattern("**/test"))
assert.True(t, IsValidPattern("**/*"))
}

func TestMatchesPattern(t *testing.T) {
assert.False(t, MatchesPattern("Test", "test"))
assert.False(t, MatchesPattern("release", "release/0.1.3"))
assert.False(t, MatchesPattern("release", "release/q3/0.1.3"))
assert.False(t, MatchesPattern("release/*", "release/q3/0.1.3"))
assert.False(t, MatchesPattern("release/*", "release"))
assert.False(t, MatchesPattern("release/**/*", "release"))
assert.False(t, MatchesPattern("test/*/tull", "test/test1/test2/tull"))
assert.False(t, MatchesPattern("(test)|(main)/*", "release/t"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1q.0.2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1..2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1.2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+\\.*", "v1.2.20-asdf"))

assert.True(t, MatchesPattern("release/*", "release/q3/0.1.3"))
assert.True(t, MatchesPattern("test/*/tull", "test/test1/test2/tull"))
assert.True(t, MatchesPattern("**", "test"))
assert.True(t, MatchesPattern("**", "test/test-test"))
assert.True(t, MatchesPattern("*/**/*", "test/test2/test3"))
assert.True(t, MatchesPattern("test/**/test3", "test/test2/test3"))
assert.True(t, MatchesPattern("test/**/test3", "test/test2/test3"))
assert.True(t, MatchesPattern(".**", "test/test-test"))
assert.True(t, MatchesPattern("**", "test-test"))
assert.True(t, MatchesPattern("test", "test"))
assert.True(t, MatchesPattern("*", "test"))
assert.True(t, MatchesPattern("*", "test/test-test"))
assert.True(t, MatchesPattern(".*", "test/test-test"))
assert.True(t, MatchesPattern("*", "test-test"))
assert.True(t, MatchesPattern("test/*", "test/test"))
assert.True(t, MatchesPattern("*", "test/test"))
assert.True(t, MatchesPattern("te??", "test"))
assert.True(t, MatchesPattern("??st", "test"))
assert.True(t, MatchesPattern("*", "test"))
Expand All @@ -48,8 +75,12 @@ func TestMatchesPattern(t *testing.T) {
assert.True(t, MatchesPattern("release/**/*", "release/q3/0.1.3"))
assert.True(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1.0.2"))
assert.True(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v123.033.2112"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1q.0.2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1..2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+", "v1.2"))
assert.False(t, MatchesPattern("v\\d+\\.\\d+\\.\\d+\\.*", "v1.2.20-asdf"))
assert.True(t, MatchesPattern("(test)|(main)/*", "test/t"))
assert.True(t, MatchesPattern("(test)|(main)/*", "main/t"))
}

func TestMatchesPattern2(t *testing.T) {
replace := strings.NewReplacer("**", "*", ".**", ".*", "*", ".*", "..*", ".*").Replace("*/w*f**f*.***.**.*")
assert.NotEmpty(t, replace)
//assert.True(t, MatchesPattern(".**", "test/test-test"))
}

0 comments on commit 4c08e2b

Please sign in to comment.