Merge lp:~tasdomas/lpad/fix-value-test into lp:lpad

Proposed by Domas Monkus
Status: Needs review
Proposed branch: lp:~tasdomas/lpad/fix-value-test
Merge into: lp:lpad
Diff against target: 35 lines (+7/-4)
1 file modified
suite_test.go (+7/-4)
To merge this branch: bzr merge lp:~tasdomas/lpad/fix-value-test
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+194936@code.launchpad.net

Commit message

Send a copy of the request to the requests channel in TestHTTPServer.

Description of the change

Send a copy of the request to the requests channel in TestHTTPServer.

It appears that golang's http server calls writeHeader after Flush, which causes the body of the request to be consumed.

To post a comment you must log in.

Unmerged revisions

65. By Domas Monkus

Fix value test - send a copy of http.Request to channel.

It appears that golang's http server calls writeHeader after Flush, which causes the body of the the
request to be consumed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'suite_test.go'
2--- suite_test.go 2011-12-06 03:12:04 +0000
3+++ suite_test.go 2013-11-12 20:24:24 +0000
4@@ -29,7 +29,7 @@
5
6 type HTTPSuite struct{}
7
8-var testServer = NewTestHTTPServer("http://localhost:4444", 5 * time.Second)
9+var testServer = NewTestHTTPServer("http://localhost:4444", 5*time.Second)
10
11 func (s *HTTPSuite) SetUpSuite(c *C) {
12 testServer.Start()
13@@ -111,7 +111,12 @@
14 if err != nil {
15 panic(err)
16 }
17- s.request <- req
18+ // make a copy of the request
19+ reqCopy := *req
20+ // make a copy of the body too
21+ reqCopy.Body = ioutil.NopCloser(bytes.NewBuffer(data))
22+
23+ s.request <- &reqCopy
24 var resp *testResponse
25 select {
26 case resp = <-s.response:
27@@ -129,8 +134,6 @@
28 w.WriteHeader(resp.Status)
29 }
30 w.Write([]byte(resp.Body))
31- // WriteHeader consumes the body per RFC2616. Restore it.
32- req.Body = ioutil.NopCloser(bytes.NewBuffer(data))
33 }
34
35 func (s *TestHTTPServer) WaitRequest() *http.Request {

Subscribers

People subscribed via source and target branches