(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func 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 | |
| 141 | func TestRemoteIPHandlerIPv6(t *testing.T) { |
| 142 | out := &bytes.Buffer{} |
nothing calls this directly
no test coverage detected