-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
params_test.go
43 lines (36 loc) · 1.05 KB
/
params_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package fuego
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParsePathParams(t *testing.T) {
require.Equal(t, []string(nil), parsePathParams("/"))
require.Equal(t, []string(nil), parsePathParams("/item/"))
require.Equal(t, []string{"user"}, parsePathParams("POST /item/{user}"))
require.Equal(t, []string{"user"}, parsePathParams("/item/{user}"))
require.Equal(t, []string{"user", "id"}, parsePathParams("/item/{user}/{id}"))
require.Equal(t, []string{"$"}, parsePathParams("/item/{$}"))
require.Equal(t, []string{"user"}, parsePathParams("POST alt.com/item/{user}"))
}
func BenchmarkParsePathParams(b *testing.B) {
b.Run("empty", func(b *testing.B) {
for range b.N {
parsePathParams("/")
}
})
b.Run("several path params", func(b *testing.B) {
for range b.N {
parsePathParams("/item/{user}/{id}")
}
})
}
func FuzzParsePathParams(f *testing.F) {
f.Add("/item/{user}")
f.Add("/item/")
f.Add("/item/{user}/{id}")
f.Add("POST /item/{user}")
f.Add("")
f.Fuzz(func(t *testing.T, data string) {
parsePathParams(data)
})
}