Skip to content

Commit 64c4950

Browse files
author
yonbiaoxiao
committed
improve the test coverage for context.go
1 parent 622f5e3 commit 64c4950

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

context_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ func BenchmarkAllocXML(b *testing.B) {
7272
}
7373
}
7474

75+
func BenchmarkRealIPForHeaderXForwardFor(b *testing.B) {
76+
c := context{request: &http.Request{
77+
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1, 127.0.1.1, "}},
78+
}}
79+
for i := 0; i < b.N; i++ {
80+
c.RealIP()
81+
}
82+
}
83+
7584
func (t *Template) Render(w io.Writer, name string, data interface{}, c Context) error {
7685
return t.templates.ExecuteTemplate(w, name, data)
7786
}
@@ -847,6 +856,14 @@ func TestContext_RealIP(t *testing.T) {
847856
},
848857
"127.0.0.1",
849858
},
859+
{
860+
&context{
861+
request: &http.Request{
862+
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1"}},
863+
},
864+
},
865+
"127.0.0.1",
866+
},
850867
{
851868
&context{
852869
request: &http.Request{
@@ -871,12 +888,3 @@ func TestContext_RealIP(t *testing.T) {
871888
testify.Equal(t, tt.s, tt.c.RealIP())
872889
}
873890
}
874-
875-
func BenchmarkRealIPForHeaderXForwardFor(b *testing.B) {
876-
c := context{request: &http.Request{
877-
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1, 127.0.1.1, "}},
878-
}}
879-
for i := 0; i < b.N; i++ {
880-
c.RealIP()
881-
}
882-
}

0 commit comments

Comments
 (0)