MCPcopy
hub / github.com/rs/zerolog / TestRemoteAddrHandler

Function TestRemoteAddrHandler

hlog/hlog_test.go:93–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestRemoteAddrHandler(t *testing.T) {
94 out := &bytes.Buffer{}
95 r := &http.Request{
96 RemoteAddr: "1.2.3.4:1234",
97 }
98 h := RemoteAddrHandler("ip")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
99 l := FromRequest(r)
100 l.Log().Msg("")
101 }))
102 h = NewHandler(zerolog.New(out))(h)
103 h.ServeHTTP(nil, r)
104 if want, got := `{"ip":"1.2.3.4:1234"}`+"\n", decodeIfBinary(out); want != got {
105 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
106 }
107}
108
109func TestRemoteAddrHandlerIPv6(t *testing.T) {
110 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
RemoteAddrHandlerFunction · 0.85
FromRequestFunction · 0.85
NewHandlerFunction · 0.85
decodeIfBinaryFunction · 0.85
MsgMethod · 0.80
LogMethod · 0.65

Tested by

no test coverage detected