github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zpprof/pprof_test.go (about) 1 package zpprof 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "strings" 7 "testing" 8 9 "github.com/sohaha/zlsgo" 10 "github.com/sohaha/zlsgo/znet" 11 ) 12 13 func TestListenAndServe(t *testing.T) { 14 _ = ListenAndServe("127.0.0.1:67890") 15 } 16 17 func TestRegister(t *testing.T) { 18 tt := zlsgo.NewTest(t) 19 r := znet.New("pprof-test") 20 r.SetMode(znet.DebugMode) 21 Register(r, "666") 22 w := httptest.NewRecorder() 23 req, _ := http.NewRequest("GET", "/debug?token=666", strings.NewReader("")) 24 r.ServeHTTP(w, req) 25 t.Log(w.Body.String()) 26 tt.Equal(200, w.Code) 27 28 w = httptest.NewRecorder() 29 req, _ = http.NewRequest("GET", "/debug", nil) 30 r.ServeHTTP(w, req) 31 t.Log(w.Body.String()) 32 tt.Equal(401, w.Code) 33 }