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

Function TestRemoteIPHandlerIPv6

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

Source from the content-addressed store, hash-verified

139}
140
141func TestRemoteIPHandlerIPv6(t *testing.T) {
142 out := &bytes.Buffer{}
143 r := &http.Request{
144 RemoteAddr: "[2001:db8:a0b:12f0::1]:1234",
145 }
146 h := RemoteIPHandler("ip")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
147 l := FromRequest(r)
148 l.Log().Msg("")
149 }))
150 h = NewHandler(zerolog.New(out))(h)
151 h.ServeHTTP(nil, r)
152 if want, got := `{"ip":"2001:db8:a0b:12f0::1"}`+"\n", decodeIfBinary(out); want != got {
153 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
154 }
155}
156
157func TestUserAgentHandler(t *testing.T) {
158 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