Skip to content

Commit

Permalink
net/http: convert TestSetsRemoteAddr to use clientServerTest
Browse files Browse the repository at this point in the history
This is an example of converting an old HTTP/1-only test to test
against both HTTP/1 and HTTP/2.

Please send more of these!

Also, for comparing the http.Transport's responses between HTTP/1 and
HTTP/2, see clientserver_test.go's h12Compare type and tests using
h12Compare. Sometimes that's the more appropriate option.

Change-Id: Iea24d844481efd5849173b60e15dcc561a32b88f
Reviewed-on: https://go-review.googlesource.com/17409
Reviewed-by: Burcu Dogan <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
bradfitz committed Dec 4, 2015
1 parent 30b87bb commit 1ea31c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/net/http/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,17 @@ func TestHandlersCanSetConnectionClose10(t *testing.T) {
}))
}

func TestSetsRemoteAddr(t *testing.T) {
func TestSetsRemoteAddr_h1(t *testing.T) { testSetsRemoteAddr(t, false) }
func TestSetsRemoteAddr_h2(t *testing.T) { testSetsRemoteAddr(t, true) }

func testSetsRemoteAddr(t *testing.T, h2 bool) {
defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
fmt.Fprintf(w, "%s", r.RemoteAddr)
}))
defer ts.Close()
defer cst.close()

res, err := Get(ts.URL)
res, err := cst.c.Get(cst.ts.URL)
if err != nil {
t.Fatalf("Get error: %v", err)
}
Expand Down

0 comments on commit 1ea31c7

Please sign in to comment.