-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathpprof_test.go
72 lines (67 loc) · 1.42 KB
/
pprof_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2017 LabStack and Echo contributors
package pprof
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
)
func TestPProfRegisterDefaualtPrefix(t *testing.T) {
var pprofPaths = []struct {
path string
}{
{"/"},
{"/allocs"},
{"/block"},
{"/cmdline"},
{"/goroutine"},
{"/heap"},
{"/mutex"},
{"/profile?seconds=1"},
{"/symbol"},
{"/symbol"},
{"/threadcreate"},
{"/trace"},
}
for _, tt := range pprofPaths {
t.Run(tt.path, func(t *testing.T) {
e := echo.New()
Register(e)
req, _ := http.NewRequest(http.MethodGet, DefaultPrefix+tt.path, nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, rec.Code, http.StatusOK)
})
}
}
func TestPProfRegisterCustomPrefix(t *testing.T) {
var pprofPaths = []struct {
path string
}{
{"/"},
{"/allocs"},
{"/block"},
{"/cmdline"},
{"/goroutine"},
{"/heap"},
{"/mutex"},
{"/profile?seconds=1"},
{"/symbol"},
{"/symbol"},
{"/threadcreate"},
{"/trace"},
}
for _, tt := range pprofPaths {
t.Run(tt.path, func(t *testing.T) {
e := echo.New()
pprofPrefix := "/myapp/pprof"
Register(e, pprofPrefix)
req, _ := http.NewRequest(http.MethodGet, pprofPrefix+tt.path, nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, rec.Code, http.StatusOK)
})
}
}