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
=== modified file 'suite_test.go'
--- suite_test.go 2011-12-06 03:12:04 +0000
+++ suite_test.go 2013-11-12 20:24:24 +0000
@@ -29,7 +29,7 @@
2929
30type HTTPSuite struct{}30type HTTPSuite struct{}
3131
32var testServer = NewTestHTTPServer("http://localhost:4444", 5 * time.Second)32var testServer = NewTestHTTPServer("http://localhost:4444", 5*time.Second)
3333
34func (s *HTTPSuite) SetUpSuite(c *C) {34func (s *HTTPSuite) SetUpSuite(c *C) {
35 testServer.Start()35 testServer.Start()
@@ -111,7 +111,12 @@
111 if err != nil {111 if err != nil {
112 panic(err)112 panic(err)
113 }113 }
114 s.request <- req114 // make a copy of the request
115 reqCopy := *req
116 // make a copy of the body too
117 reqCopy.Body = ioutil.NopCloser(bytes.NewBuffer(data))
118
119 s.request <- &reqCopy
115 var resp *testResponse120 var resp *testResponse
116 select {121 select {
117 case resp = <-s.response:122 case resp = <-s.response:
@@ -129,8 +134,6 @@
129 w.WriteHeader(resp.Status)134 w.WriteHeader(resp.Status)
130 }135 }
131 w.Write([]byte(resp.Body))136 w.Write([]byte(resp.Body))
132 // WriteHeader consumes the body per RFC2616. Restore it.
133 req.Body = ioutil.NopCloser(bytes.NewBuffer(data))
134}137}
135138
136func (s *TestHTTPServer) WaitRequest() *http.Request {139func (s *TestHTTPServer) WaitRequest() *http.Request {

Subscribers

People subscribed via source and target branches