test: add more tests (#1150)

master
Kevin Wan 3 years ago committed by GitHub
parent a944a7fd7e
commit 5636bf4955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,5 +10,6 @@ func GetRemoteAddr(r *http.Request) string {
if len(v) > 0 { if len(v) > 0 {
return v return v
} }
return r.RemoteAddr return r.RemoteAddr
} }

@ -16,3 +16,10 @@ func TestGetRemoteAddr(t *testing.T) {
r.Header.Set(xForwardedFor, host) r.Header.Set(xForwardedFor, host)
assert.Equal(t, host, GetRemoteAddr(r)) assert.Equal(t, host, GetRemoteAddr(r))
} }
func TestGetRemoteAddrNoHeader(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
assert.Nil(t, err)
assert.True(t, len(GetRemoteAddr(r)) == 0)
}

Loading…
Cancel
Save