mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
make api match intent with less specific type
This commit is contained in:
parent
45f9f39b51
commit
e348b939bf
@ -165,7 +165,7 @@ func StringDiff(a, b string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Takes a list of strings and compiles them into a list of regular expressions
|
// Takes a list of strings and compiles them into a list of regular expressions
|
||||||
func CompileRegexps(regexpStrings StringList) ([]*regexp.Regexp, error) {
|
func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
|
||||||
regexps := []*regexp.Regexp{}
|
regexps := []*regexp.Regexp{}
|
||||||
for _, regexpStr := range regexpStrings {
|
for _, regexpStr := range regexpStrings {
|
||||||
r, err := regexp.Compile(regexpStr)
|
r, err := regexp.Compile(regexpStr)
|
||||||
|
@ -206,3 +206,28 @@ func TestStringDiff(t *testing.T) {
|
|||||||
t.Errorf("diff returned %v", diff)
|
t.Errorf("diff returned %v", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompileRegex(t *testing.T) {
|
||||||
|
uncompiledRegexes := []string{"endsWithMe$", "^startingWithMe"}
|
||||||
|
regexes, err := CompileRegexps(uncompiledRegexes)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to compile legal regexes: '%v': %v", uncompiledRegexes, err)
|
||||||
|
}
|
||||||
|
if len(regexes) != len(uncompiledRegexes) {
|
||||||
|
t.Errorf("Wrong number of regexes returned: '%v': %v", uncompiledRegexes, regexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !regexes[0].MatchString("Something that endsWithMe") {
|
||||||
|
t.Errorf("Wrong regex returned: '%v': %v", uncompiledRegexes[0], regexes[0])
|
||||||
|
}
|
||||||
|
if regexes[0].MatchString("Something that doesn't endsWithMe.") {
|
||||||
|
t.Errorf("Wrong regex returned: '%v': %v", uncompiledRegexes[0], regexes[0])
|
||||||
|
}
|
||||||
|
if !regexes[1].MatchString("startingWithMe is very important") {
|
||||||
|
t.Errorf("Wrong regex returned: '%v': %v", uncompiledRegexes[1], regexes[1])
|
||||||
|
}
|
||||||
|
if regexes[1].MatchString("not startingWithMe should fail") {
|
||||||
|
t.Errorf("Wrong regex returned: '%v': %v", uncompiledRegexes[1], regexes[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user