MCPcopy
hub / github.com/hashicorp/go-getter / TestHttpGetter_cleanhttp

Function TestHttpGetter_cleanhttp

get_http_test.go:510–554  ·  view source on GitHub ↗

verify that the default httpClient no longer comes from http.DefaultClient

(t *testing.T)

Source from the content-addressed store, hash-verified

508
509// verify that the default httpClient no longer comes from http.DefaultClient
510func TestHttpGetter_cleanhttp(t *testing.T) {
511 ln := testHttpServer(t)
512 defer ln.Close()
513
514 // break the default http client
515 http.DefaultClient.Transport = errRoundTripper{}
516 defer func() {
517 http.DefaultClient.Transport = http.DefaultTransport
518 }()
519 ctx := context.Background()
520
521 g := new(HttpGetter)
522 dst := testing_helper.TempDir(t)
523 defer os.RemoveAll(dst)
524
525 var u url.URL
526 u.Scheme = "http"
527 u.Host = ln.Addr().String()
528 u.Path = "/header"
529
530 req := &Request{
531 Dst: dst,
532 Src: u.String(),
533 u: &u,
534 GetMode: ModeDir,
535 }
536
537 // Get it, which should error because it uses the file protocol.
538 err := g.Get(ctx, req)
539 if !strings.Contains(err.Error(), "no getter available for X-Terraform-Get source protocol:") {
540 t.Fatalf("unexpected error: %v", err)
541 }
542 // But, using a wrapper client with a file getter will work.
543 c := &Client{
544 Getters: []Getter{
545 g,
546 new(FileGetter),
547 },
548 }
549
550 if _, err = c.Get(ctx, req); err != nil {
551 t.Fatalf("err: %s", err)
552 }
553
554}
555
556func TestHttpGetter__RespectsContextCanceled(t *testing.T) {
557 ctx, cancel := context.WithCancel(context.Background())

Callers

nothing calls this directly

Calls 6

GetMethod · 0.95
testHttpServerFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected