Skip to content

Commit

Permalink
test: path characters regexp validation (kubernetes-sigs#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
em-r committed Jan 19, 2023
1 parent 7d408be commit 47c43be
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apis/v1beta1/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package validation

import (
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1140,3 +1141,40 @@ func TestValidateHTTPRouteTypeMatchesField(t *testing.T) {
})
}
}

func TestValidPathCharactersRegExp(t *testing.T) {
r, err := regexp.Compile(validPathCharacters)
assert.NoError(t, err)

tests := []struct {
name string
sequence string
isValid bool
}{{
name: "valid sequence of alphabetic characters",
sequence: "mypath",
isValid: true,
}, {
name: "valid sequence of alphanumeric characters",
sequence: "mypath0123",
isValid: true,
}, {
name: "valid mix of alphanumeric characters and special characters",
sequence: "my%20path/123",
isValid: true,
}, {
name: "invalid sequence of special characters",
sequence: "[]",
isValid: false,
}, {
name: "invalid mix of alphanumeric characters of special characters",
sequence: "my[/]path",
isValid: false,
}}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.isValid, r.MatchString(tc.sequence))
})
}
}

0 comments on commit 47c43be

Please sign in to comment.