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

Function TestRemoteAddrHandlerIPv6

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

Source from the content-addressed store, hash-verified

107}
108
109func TestRemoteAddrHandlerIPv6(t *testing.T) {
110 out := &bytes.Buffer{}
111 r := &http.Request{
112 RemoteAddr: "[2001:db8:a0b:12f0::1]:1234",
113 }
114 h := RemoteAddrHandler("ip")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
115 l := FromRequest(r)
116 l.Log().Msg("")
117 }))
118 h = NewHandler(zerolog.New(out))(h)
119 h.ServeHTTP(nil, r)
120 if want, got := `{"ip":"[2001:db8:a0b:12f0::1]:1234"}`+"\n", decodeIfBinary(out); want != got {
121 t.Errorf("Invalid log output, got: %s, want: %s", got, want)
122 }
123}
124
125func TestRemoteIPHandler(t *testing.T) {
126 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