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

Function TestHttpGetter_authNetrc

get_http_test.go:452–500  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

450}
451
452func TestHttpGetter_authNetrc(t *testing.T) {
453 ln := testHttpServer(t)
454 defer ln.Close()
455 ctx := context.Background()
456
457 g := new(HttpGetter)
458 dst := testing_helper.TempDir(t)
459 defer os.RemoveAll(dst)
460
461 var u url.URL
462 u.Scheme = "http"
463 u.Host = ln.Addr().String()
464 u.Path = "/meta"
465
466 // Write the netrc file
467 path, closer := testing_helper.TempFileWithContent(t, fmt.Sprintf(testHttpNetrc, ln.Addr().String()))
468 defer closer()
469 defer tempEnv(t, "NETRC", path)()
470
471 req := &Request{
472 Dst: dst,
473 Src: u.String(),
474 u: &u,
475 GetMode: ModeDir,
476 }
477
478 // Get it, which should error because it uses the file protocol.
479 err := g.Get(ctx, req)
480 if !strings.Contains(err.Error(), "no getter available for X-Terraform-Get source protocol:") {
481 t.Fatalf("unexpected error: %v", err)
482 }
483 // But, using a wrapper client with a file getter will work.
484 c := &Client{
485 Getters: []Getter{
486 g,
487 new(FileGetter),
488 },
489 }
490
491 if _, err = c.Get(ctx, req); err != nil {
492 t.Fatalf("err: %s", err)
493 }
494
495 // Verify the main file exists
496 mainPath := filepath.Join(dst, "main.tf")
497 if _, err := os.Stat(mainPath); err != nil {
498 t.Fatalf("err: %s", err)
499 }
500}
501
502// test round tripper that only returns an error
503type errRoundTripper struct{}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected