parent
8a22221f9c
commit
6a02fd2641
7 changed files with 54 additions and 65 deletions
@ -1,13 +0,0 @@ |
||||
package run |
||||
|
||||
import "strings" |
||||
|
||||
// hasAtLeastOnePrefix checks whether the key has begins with at least one of prefixes.
|
||||
func hasAtLeastOnePrefix(key string, prefixes []string) bool { |
||||
for _, prefix := range prefixes { |
||||
if strings.HasPrefix(key, prefix) { |
||||
return true |
||||
} |
||||
} |
||||
return false |
||||
} |
@ -1,40 +0,0 @@ |
||||
package run |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func TestHasAtLeastOnePrefix(t *testing.T) { |
||||
|
||||
cases := []struct { |
||||
key string |
||||
prefixes []string |
||||
expectResult bool |
||||
}{ |
||||
{ |
||||
// no prefix provided
|
||||
"a", |
||||
[]string{}, |
||||
false, |
||||
}, |
||||
{ |
||||
// has prefix
|
||||
"abc", |
||||
[]string{"ab"}, |
||||
true, |
||||
}, |
||||
{ |
||||
// does NOT have prefix
|
||||
"abc", |
||||
[]string{"edf", "wab"}, |
||||
false, |
||||
}, |
||||
} |
||||
|
||||
for _, c := range cases { |
||||
result := hasAtLeastOnePrefix(c.key, c.prefixes) |
||||
assert.Equal(t, c.expectResult, result) |
||||
} |
||||
} |
Loading…
Reference in new issue