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

Function TestFetch

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

Source from the content-addressed store, hash-verified

192func (testFile) Close() error { return nil }
193
194func TestFetch(t *testing.T) {
195 const path = "testdata/"
196 type testcase struct {
197 source, execName string
198 wantErr bool
199 }
200 ts := []testcase{
201 {path + "go.crc32.cpu", "", false},
202 {path + "go.nomappings.crash", "/bin/gotest.exe", false},
203 {"http://localhost/profile?file=cppbench.cpu", "", false},
204 {"./missing", "", true},
205 }
206 // Test that paths with a colon character are recognized as file paths
207 // if the file exists, rather than as a URL. We have to skip this test
208 // on Windows since the colon char is not allowed in Windows paths.
209 if runtime.GOOS != "windows" {
210 src := filepath.Join(path, "go.crc32.cpu")
211 dst := filepath.Join(t.TempDir(), "go.crc32.cpu_2023-11-11_01:02:03")
212 data, err := os.ReadFile(src)
213 if err != nil {
214 t.Fatalf("read src file %s failed: %#v", src, err)
215 }
216 err = os.WriteFile(dst, data, 0644)
217 if err != nil {
218 t.Fatalf("create dst file %s failed: %#v", dst, err)
219 }
220 ts = append(ts, testcase{dst, "", false})
221 }
222 for _, tc := range ts {
223 t.Run(tc.source, func(t *testing.T) {
224 p, _, _, err := grabProfile(&source{ExecName: tc.execName}, tc.source, nil, testObj{}, &proftest.TestUI{T: t}, &httpTransport{})
225 if tc.wantErr {
226 if err == nil {
227 t.Fatal("got no error, want an error")
228 }
229 return
230 }
231 if err != nil {
232 t.Fatalf("got error %v, want no error", err)
233 }
234 if len(p.Sample) == 0 {
235 t.Error("got zero samples, want non-zero")
236 }
237 if e := tc.execName; e != "" {
238 switch {
239 case len(p.Mapping) == 0 || p.Mapping[0] == nil:
240 t.Errorf("got no mappings, want mapping[0].execName == %s", e)
241 case p.Mapping[0].File != e:
242 t.Errorf("got mapping[0].execName == %s, want %s", p.Mapping[0].File, e)
243 }
244 }
245 })
246 }
247}
248
249func TestFetchWithBase(t *testing.T) {
250 baseConfig := currentConfig()

Callers

nothing calls this directly

Calls 1

grabProfileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…