2020-06-27 15:48:36 +00:00
|
|
|
package v1
|
2020-04-28 14:27:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-07-22 19:42:43 +00:00
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-04-28 14:27:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathsToVerificationRegexes(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
paths []string
|
|
|
|
regexes []string
|
|
|
|
err string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Empty",
|
|
|
|
regexes: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "IgnoreBadPaths",
|
|
|
|
paths: []string{"", "/", "/Account"},
|
|
|
|
regexes: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Simple",
|
|
|
|
paths: []string{"Wallet/Account"},
|
|
|
|
regexes: []string{"^Wallet/Account$"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Multiple",
|
|
|
|
paths: []string{"Wallet/Account1", "Wallet/Account2"},
|
|
|
|
regexes: []string{"^Wallet/Account1$", "^Wallet/Account2$"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "IgnoreInvalidRegex",
|
|
|
|
paths: []string{"Wallet/Account1", "Bad/***", "Wallet/Account2"},
|
|
|
|
regexes: []string{"^Wallet/Account1$", "^Wallet/Account2$"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "TidyExistingAnchors",
|
|
|
|
paths: []string{"Wallet/^.*$", "Wallet/Foo.*Bar$", "Wallet/^Account"},
|
|
|
|
regexes: []string{"^Wallet/.*$", "^Wallet/Foo.*Bar$", "^Wallet/Account$"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
regexes := pathsToVerificationRegexes(test.paths)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.Equal(t, len(test.regexes), len(regexes), "Unexpected number of regexes")
|
2020-04-28 14:27:04 +00:00
|
|
|
for i := range regexes {
|
2020-07-22 19:42:43 +00:00
|
|
|
require.Equal(t, test.regexes[i], regexes[i].String(), "Unexpected regex %d", i)
|
2020-04-28 14:27:04 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|