153 | 153 |
buf, _ := ioutil.ReadAll(resp.Body)
|
154 | 154 |
if want, have := `{"foo":"bar"}`, strings.TrimSpace(string(buf)); want != have {
|
155 | 155 |
t.Errorf("Body: want %s, have %s", want, have)
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
type noContentResponse struct{}
|
|
160 |
|
|
161 |
func (e noContentResponse) StatusCode() int { return http.StatusNoContent }
|
|
162 |
|
|
163 |
func TestEncodeNoContent(t *testing.T) {
|
|
164 |
handler := httptransport.NewServer(
|
|
165 |
context.Background(),
|
|
166 |
func(context.Context, interface{}) (interface{}, error) { return noContentResponse{}, nil },
|
|
167 |
func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil },
|
|
168 |
httptransport.EncodeJSONResponse,
|
|
169 |
)
|
|
170 |
|
|
171 |
server := httptest.NewServer(handler)
|
|
172 |
defer server.Close()
|
|
173 |
|
|
174 |
resp, err := http.Get(server.URL)
|
|
175 |
if err != nil {
|
|
176 |
t.Fatal(err)
|
|
177 |
}
|
|
178 |
if want, have := http.StatusNoContent, resp.StatusCode; want != have {
|
|
179 |
t.Errorf("StatusCode: want %d, have %d", want, have)
|
|
180 |
}
|
|
181 |
buf, _ := ioutil.ReadAll(resp.Body)
|
|
182 |
if want, have := 0, len(buf); want != have {
|
|
183 |
t.Errorf("Body: want no content, have %d bytes", have)
|
156 | 184 |
}
|
157 | 185 |
}
|
158 | 186 |
|