now we build some higher level methods on top of ReceiveRequest
(t *testing.T, method string, pathAndQuery string)
| 133 | // now we build some higher level methods on top of ReceiveRequest |
| 134 | |
| 135 | func (m *MockHttpServer) ExpectRequest(t *testing.T, method string, pathAndQuery string) *RequestWrapper { |
| 136 | r, ok := m.ReceiveRequest() |
| 137 | if !ok { // this means the channel was closed |
| 138 | // don't fatal, there'll be some other assertion failure too, and we want to let that have a chance to print |
| 139 | t.Errorf("ExpectRequest %s %s failed; channel closed", method, pathAndQuery) |
| 140 | return &RequestWrapper{&http.Request{}, m} |
| 141 | } |
| 142 | |
| 143 | rPathAndQuery := r.URL.Path |
| 144 | if r.URL.RawPath != "" { // RawPath may not be set, but if it is it should be used in preference to Path |
| 145 | rPathAndQuery = r.URL.RawPath |
| 146 | } |
| 147 | if r.URL.RawQuery != "" { |
| 148 | rPathAndQuery = fmt.Sprintf("%s?%s", rPathAndQuery, r.URL.RawQuery) |
| 149 | } |
| 150 | assert.Equal(t, method, r.Method) |
| 151 | assert.Equal(t, pathAndQuery, rPathAndQuery) |
| 152 | |
| 153 | return &RequestWrapper{r, m} |
| 154 | } |
| 155 | |
| 156 | type RequestWrapper struct { |
| 157 | // in case you need it |