Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions httpbin/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,25 @@ func TestIP(t *testing.T) {
assert.Equal(t, result.Origin, tc.wantOrigin, "incorrect origin")
})
}

t.Run("via real connection", func(t *testing.T) {
// (*Request).RemoteAddr includes the local port for real incoming TCP
// connections but not for direct ServeHTTP calls as the used in the
// httptest.NewRecorder tests above, so we need to use a real server
// to verify handling of both cases.
srv := httptest.NewServer(app)
defer srv.Close()

resp, err := client.Get(srv.URL + "/ip")
assert.NilError(t, err)
defer resp.Body.Close()

assert.StatusCode(t, resp, http.StatusOK)
assert.ContentType(t, resp, jsonContentType)

result := must.Unmarshal[ipResponse](t, resp.Body)
assert.Equal(t, result.Origin, "127.0.0.1", "incorrect origin")
})
}

func TestUserAgent(t *testing.T) {
Expand Down
Loading