mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-20 00:02:16 +08:00
path: update path_test.go to the latest code
This commit is contained in:
parent
2e59578867
commit
c7977d42f2
52
path_test.go
52
path_test.go
@ -6,14 +6,17 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cleanTests = []struct {
|
type cleanPathTest struct {
|
||||||
path, result string
|
path, result string
|
||||||
}{
|
}
|
||||||
|
|
||||||
|
var cleanTests = []cleanPathTest{
|
||||||
// Already clean
|
// Already clean
|
||||||
{"/", "/"},
|
{"/", "/"},
|
||||||
{"/abc", "/abc"},
|
{"/abc", "/abc"},
|
||||||
@ -84,6 +87,51 @@ func TestPathCleanMallocs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkPathClean(b *testing.B) {
|
func BenchmarkPathClean(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
for _, test := range cleanTests {
|
||||||
|
cleanPath(test.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func genLongPaths() (testPaths []cleanPathTest) {
|
||||||
|
for i := 1; i <= 1234; i++ {
|
||||||
|
ss := strings.Repeat("a", i)
|
||||||
|
|
||||||
|
correctPath := "/" + ss
|
||||||
|
testPaths = append(testPaths, cleanPathTest{
|
||||||
|
path: correctPath,
|
||||||
|
result: correctPath,
|
||||||
|
}, cleanPathTest{
|
||||||
|
path: ss,
|
||||||
|
result: correctPath,
|
||||||
|
}, cleanPathTest{
|
||||||
|
path: "//" + ss,
|
||||||
|
result: correctPath,
|
||||||
|
}, cleanPathTest{
|
||||||
|
path: "/" + ss + "/b/..",
|
||||||
|
result: correctPath,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPathCleanLong(t *testing.T) {
|
||||||
|
cleanTests := genLongPaths()
|
||||||
|
|
||||||
|
for _, test := range cleanTests {
|
||||||
|
assert.Equal(t, test.result, cleanPath(test.path))
|
||||||
|
assert.Equal(t, test.result, cleanPath(test.result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkPathCleanLong(b *testing.B) {
|
||||||
|
cleanTests := genLongPaths()
|
||||||
|
b.ResetTimer()
|
||||||
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, test := range cleanTests {
|
for _, test := range cleanTests {
|
||||||
cleanPath(test.path)
|
cleanPath(test.path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user