MCPcopy Create free account
hub / github.com/google/pprof / TestHTTPSInsecure

Function TestHTTPSInsecure

internal/driver/fetch_test.go:612–683  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

610}
611
612func TestHTTPSInsecure(t *testing.T) {
613 if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
614 t.Skip("test assumes tcp available")
615 }
616 saveHome := os.Getenv(homeEnv())
617 tempdir, err := os.MkdirTemp("", "home")
618 if err != nil {
619 t.Fatal("creating temp dir: ", err)
620 }
621 defer os.RemoveAll(tempdir)
622
623 // pprof writes to $HOME/pprof by default which is not necessarily
624 // writeable (e.g. on a Debian build) so set $HOME to something we
625 // know we can write to for the duration of the test.
626 os.Setenv(homeEnv(), tempdir)
627 defer os.Setenv(homeEnv(), saveHome)
628
629 baseConfig := currentConfig()
630 defer setCurrentConfig(baseConfig)
631
632 tlsCert, _, _ := selfSignedCert(t, "")
633 tlsConfig := &tls.Config{Certificates: []tls.Certificate{tlsCert}}
634
635 l, err := tls.Listen("tcp", "localhost:0", tlsConfig)
636 if err != nil {
637 t.Fatalf("net.Listen: got error %v, want no error", err)
638 }
639
640 donec := make(chan error, 1)
641 go func(donec chan<- error) {
642 donec <- http.Serve(l, nil)
643 }(donec)
644 defer func() {
645 if got, want := <-donec, closedError(); !strings.Contains(got.Error(), want) {
646 t.Fatalf("Serve got error %v, want %q", got, want)
647 }
648 }()
649 defer l.Close()
650
651 outputTempFile, err := os.CreateTemp("", "profile_output")
652 if err != nil {
653 t.Fatalf("Failed to create tempfile: %v", err)
654 }
655 defer os.Remove(outputTempFile.Name())
656 defer outputTempFile.Close()
657
658 address := "https+insecure://" + l.Addr().String() + "/debug/pprof/goroutine"
659 s := &source{
660 Sources: []string{address},
661 Timeout: 10,
662 Symbolize: "remote",
663 }
664 o := &plugin.Options{
665 Obj: &binutils.Binutils{},
666 UI: &proftest.TestUI{T: t, AllowRx: "Saved profile in"},
667 HTTPTransport: transport.New(nil),
668 }
669 o.Sym = &symbolizer.Symbolizer{Obj: o.Obj, UI: o.UI}

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
homeEnvFunction · 0.85
currentConfigFunction · 0.85
setCurrentConfigFunction · 0.85
selfSignedCertFunction · 0.85
closedErrorFunction · 0.85
fetchProfilesFunction · 0.85
checkProfileHasFunctionFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…