(t *testing.T)
| 448 | } |
| 449 | |
| 450 | func TestWithHTTPClient(t *testing.T) { |
| 451 | t.Parallel() |
| 452 | |
| 453 | t.Run("nil_client", func(t *testing.T) { |
| 454 | t.Parallel() |
| 455 | |
| 456 | opts := clientOptions{} |
| 457 | err := WithHTTPClient(nil)(&opts) |
| 458 | if err == nil || err.Error() != "http client must not be nil" { |
| 459 | t.Errorf("WithHTTPClient errored: %v", err) |
| 460 | } |
| 461 | }) |
| 462 | |
| 463 | t.Run("non_nil_client", func(t *testing.T) { |
| 464 | t.Parallel() |
| 465 | |
| 466 | customClient := &http.Client{Timeout: 10 * time.Second} |
| 467 | opts := clientOptions{} |
| 468 | err := WithHTTPClient(customClient)(&opts) |
| 469 | if err != nil { |
| 470 | t.Fatalf("WithHTTPClient errored: %v", err) |
| 471 | } |
| 472 | |
| 473 | if opts.httpClient == nil { |
| 474 | t.Fatal("httpClient is nil") |
| 475 | } |
| 476 | |
| 477 | if opts.httpClient == customClient { |
| 478 | t.Error("httpClient should be a shallow copy of the provided client, but is the same instance") |
| 479 | } |
| 480 | |
| 481 | if opts.httpClient.Timeout != customClient.Timeout { |
| 482 | t.Errorf("httpClient Timeout = %v, want %v", opts.httpClient.Timeout, customClient.Timeout) |
| 483 | } |
| 484 | }) |
| 485 | } |
| 486 | |
| 487 | func TestWithTransport(t *testing.T) { |
| 488 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…