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

Function makeTestServer

internal/driver/webui_test.go:35–66  ·  view source on GitHub ↗
(t testing.TB, prof *profile.Profile)

Source from the content-addressed store, hash-verified

33)
34
35func makeTestServer(t testing.TB, prof *profile.Profile) *httptest.Server {
36 if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
37 t.Skip("test assumes tcp available")
38 }
39
40 // Custom http server creator
41 var server *httptest.Server
42 serverCreated := make(chan bool)
43 creator := func(a *plugin.HTTPServerArgs) error {
44 server = httptest.NewServer(http.HandlerFunc(
45 func(w http.ResponseWriter, r *http.Request) {
46 if h := a.Handlers[r.URL.Path]; h != nil {
47 h.ServeHTTP(w, r)
48 }
49 }))
50 serverCreated <- true
51 return nil
52 }
53
54 // Start server and wait for it to be initialized
55 go serveWebInterface("unused:1234", prof, &plugin.Options{
56 Obj: fakeObjTool{},
57 UI: &proftest.TestUI{T: t},
58 HTTPServer: creator,
59 }, false)
60 <-serverCreated
61
62 // Close the server when the test is done.
63 t.Cleanup(server.Close)
64
65 return server
66}
67
68func TestWebInterface(t *testing.T) {
69 prof := makeFakeProfile()

Callers 2

TestWebInterfaceFunction · 0.70
benchmarkURLFunction · 0.70

Calls 1

serveWebInterfaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…