Skip to content

Commit

Permalink
improve the test coverage for context.go
Browse files Browse the repository at this point in the history
  • Loading branch information
yonbiaoxiao committed Sep 16, 2020
1 parent 622f5e3 commit 64c4950
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{
Expand All @@ -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()
}
}

0 comments on commit 64c4950

Please # to comment.