// ServeHTTP is declared to make TestHTTPServer implement the http.Handler
// interface. It will handle all requests, storing information about them. You
// can use PrepareResponse method to prepare the next response, and WaitRequest
// to wait for a request (so you can test attributes of the request).
ServeHTTP is declared to make TestHTTPServer implement the http.Handler
interface. It will handle all requests, storing information about them. You
can use PrepareResponse method to prepare the next response, and WaitRequest
to wait for a request (so you can test attributes of the request).
// ServeHTTP is declared to make TestHTTPServer implement the http . Handler // interface . It will handle all requests storing information about them . You // can use PrepareResponse method to prepare the next response and WaitRequest // to wait for a request ( so you can test attributes of the request ) .
func (s *TestHTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	b, _ := ioutil.ReadAll(req.Body)
	s.body <- b
	s.Request <- req
	var resp *testResponse
	select {
	case resp = <-s.response:
	case <-time.After(s.timeout):
		log.Panicf("No response from server after %s.", s.timeout)
	}
	if resp.Status != 0 {
		w.WriteHeader(resp.Status)
	}
	w.Write([]byte(resp.Body))
}
func ( s * TestHTTPServer ) ServeHTTP ( w http . ResponseWriter , req * http . Request ) { b , _ := ioutil . ReadAll ( req . Body ) s . body <- b s . Request <- req var resp * testResponse select { case resp = <- s . response : case <- time . After ( s . timeout ) : log . Panicf ( " " , s . timeout ) } if resp . Status != 0 { w . WriteHeader ( resp . Status ) } w . Write ( [ ] byte ( resp . Body ) ) }
ServeHTTP is declared to make TestHTTPServer implement the http.Handler
interface.
ServeHTTP is declared to make TestHTTPServer implement the http . Handler interface .