(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func TestSetClient(t *testing.T) { |
| 266 | var ( |
| 267 | encode = func(context.Context, *http.Request, interface{}) error { return nil } |
| 268 | decode = func(_ context.Context, r *http.Response) (interface{}, error) { |
| 269 | t, err := ioutil.ReadAll(r.Body) |
| 270 | if err != nil { |
| 271 | return nil, err |
| 272 | } |
| 273 | return string(t), nil |
| 274 | } |
| 275 | ) |
| 276 | |
| 277 | testHttpClient := httpClientFunc(func(req *http.Request) (*http.Response, error) { |
| 278 | return &http.Response{ |
| 279 | StatusCode: http.StatusOK, |
| 280 | Request: req, |
| 281 | Body: ioutil.NopCloser(bytes.NewBufferString("hello, world!")), |
| 282 | }, nil |
| 283 | }) |
| 284 | |
| 285 | client := httptransport.NewClient( |
| 286 | "GET", |
| 287 | &url.URL{}, |
| 288 | encode, |
| 289 | decode, |
| 290 | httptransport.SetClient(testHttpClient), |
| 291 | ).Endpoint() |
| 292 | |
| 293 | resp, err := client(context.Background(), nil) |
| 294 | if err != nil { |
| 295 | t.Fatal(err) |
| 296 | } |
| 297 | if r, ok := resp.(string); !ok || r != "hello, world!" { |
| 298 | t.Fatal("Expected response to be 'hello, world!' string") |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | func TestNewExplicitClient(t *testing.T) { |
| 303 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…