(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestWebInterface(t *testing.T) { |
| 69 | prof := makeFakeProfile() |
| 70 | server := makeTestServer(t, prof) |
| 71 | haveDot := false |
| 72 | if _, err := exec.LookPath("dot"); err == nil { |
| 73 | haveDot = true |
| 74 | } |
| 75 | |
| 76 | type testCase struct { |
| 77 | path string |
| 78 | want []string |
| 79 | needDot bool |
| 80 | } |
| 81 | testcases := []testCase{ |
| 82 | {"/", []string{"F1", "F2", "F3", "testbin", "cpu"}, true}, |
| 83 | {"/top", []string{`"Name":"F2","InlineLabel":"","Flat":200,"Cum":300,"FlatFormat":"200ms","CumFormat":"300ms"}`}, false}, |
| 84 | {"/source?f=" + url.QueryEscape("F[12]"), []string{ |
| 85 | "F1", |
| 86 | "F2", |
| 87 | `\. +300ms .*f1:asm`, // Cumulative count for F1 |
| 88 | "200ms +300ms .*f2:asm", // Flat + cumulative count for F2 |
| 89 | }, false}, |
| 90 | {"/peek?f=" + url.QueryEscape("F[12]"), |
| 91 | []string{"300ms.*F1", "200ms.*300ms.*F2"}, false}, |
| 92 | {"/disasm?f=" + url.QueryEscape("F[12]"), |
| 93 | []string{"f1:asm", "f2:asm"}, false}, |
| 94 | {"/flamegraph", []string{ |
| 95 | "File: testbin", |
| 96 | // Check that interesting frames are included. |
| 97 | `\bF1\b`, |
| 98 | `\bF2\b`, |
| 99 | // Check new view JS is included. |
| 100 | `function stackViewer`, |
| 101 | // Check new view CSS is included. |
| 102 | "#stack-chart {", |
| 103 | }, false}, |
| 104 | } |
| 105 | for _, c := range testcases { |
| 106 | if c.needDot && !haveDot { |
| 107 | t.Log("skipping", c.path, "since dot (graphviz) does not seem to be installed") |
| 108 | continue |
| 109 | } |
| 110 | res, err := http.Get(server.URL + c.path) |
| 111 | if err != nil { |
| 112 | t.Error("could not fetch", c.path, err) |
| 113 | continue |
| 114 | } |
| 115 | data, err := io.ReadAll(res.Body) |
| 116 | if err != nil { |
| 117 | t.Error("could not read response", c.path, err) |
| 118 | continue |
| 119 | } |
| 120 | result := string(data) |
| 121 | for _, w := range c.want { |
| 122 | if match, _ := regexp.MatchString(w, result); !match { |
| 123 | t.Errorf("response for %s does not match "+ |
| 124 | "expected pattern '%s'; "+ |
| 125 | "actual result:\n%s", c.path, w, result) |
nothing calls this directly
no test coverage detected
searching dependent graphs…