mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
helper/backend: benchmark route
This commit is contained in:
@@ -5,6 +5,29 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkBackendRoute(b *testing.B) {
|
||||
patterns := []string{
|
||||
"foo",
|
||||
"bar/(?P<name>.+?)",
|
||||
"baz/(?P<name>what)",
|
||||
`aws/policy/(?P<policy>\w)`,
|
||||
`aws/(?P<policy>\w)`,
|
||||
}
|
||||
|
||||
backend := &Backend{Paths: make([]*Path, 0, len(patterns))}
|
||||
for _, p := range patterns {
|
||||
backend.Paths = append(backend.Paths, &Path{Pattern: p})
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
p := backend.Route("aws/policy/foo")
|
||||
if p == nil {
|
||||
b.Fatal("p should not be nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackendRoute(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
Patterns []string
|
||||
|
||||
Reference in New Issue
Block a user