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

Function TestRemoteIPHandler

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

Source from the content-addressed store, hash-verified

123}
124
125func TestRemoteIPHandler(t *testing.T) {
126 out := &bytes.Buffer{}
127 r := &http.Request{
128 RemoteAddr: "1.2.3.4:1234",
129 }
130 h := RemoteIPHandler("ip")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
131 l := FromRequest(r)
132 l.Log().Msg("")
133 }))
134 h = NewHandler(zerolog.New(out))(h)
135 h.ServeHTTP(nil, r)
136 if want, got := `{"ip":"1.2.3.4"}`+"\n", decodeIfBinary(out); want != got {
137 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
138 }
139}
140
141func TestRemoteIPHandlerIPv6(t *testing.T) {
142 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected