1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

improve the test coverage for context.go

This commit is contained in:
yonbiaoxiao 2020-09-16 10:36:43 +08:00
parent 622f5e33d4
commit 64c4950996

View File

@ -72,6 +72,15 @@ func BenchmarkAllocXML(b *testing.B) {
}
}
func BenchmarkRealIPForHeaderXForwardFor(b *testing.B) {
c := context{request: &http.Request{
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1, 127.0.1.1, "}},
}}
for i := 0; i < b.N; i++ {
c.RealIP()
}
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
@ -847,6 +856,14 @@ func TestContext_RealIP(t *testing.T) {
},
"127.0.0.1",
},
{
&context{
request: &http.Request{
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1"}},
},
},
"127.0.0.1",
},
{
&context{
request: &http.Request{
@ -871,12 +888,3 @@ func TestContext_RealIP(t *testing.T) {
testify.Equal(t, tt.s, tt.c.RealIP())
}
}
func BenchmarkRealIPForHeaderXForwardFor(b *testing.B) {
c := context{request: &http.Request{
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1, 127.0.1.1, "}},
}}
for i := 0; i < b.N; i++ {
c.RealIP()
}
}