MCPcopy Index your code
hub / github.com/google/go-github / TestWithHTTPClient

Function TestWithHTTPClient

github/github_test.go:450–485  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

448}
449
450func 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
487func TestWithTransport(t *testing.T) {
488 t.Parallel()

Callers

nothing calls this directly

Calls 3

WithHTTPClientFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…