refactor:简化main函数中pprof的关闭调用

This commit is contained in:
tangerineyu
2026-03-26 12:17:05 +08:00
parent 9a0ba45a51
commit 145bf3fa86
4 changed files with 51 additions and 28 deletions

View File

@@ -17,15 +17,26 @@ func TestNewPprofMux(t *testing.T) {
t.Errorf("Expected status code 200, got %d", rr.Code)
}
}
func TestStartPprofServerWithDisabled(t *testing.T) {
func TestNewPprofServerWithDisabled(t *testing.T) {
t.Parallel()
server, err := StartPprofServer("api", false, "localhost:6060")
pprofServer, err := NewPprofServer("api", false, "localhost:6060")
if err != nil {
t.Fatalf("Failed to start pprof server: %v", err)
t.Fatalf("Failed to create pprof server: %v", err)
}
if server != nil {
t.Fatalf("Expected nil server when pprof is disabled, got non-nil")
if pprofServer != nil {
t.Fatalf("Expected nil pprof server when disabled, got non-nil")
}
}
func TestPprofServerCloseWithDisabledServer(t *testing.T) {
t.Parallel()
pprofServer, err := NewPprofServer("api", false, "localhost:6060")
if err != nil {
t.Fatalf("Failed to create pprof server: %v", err)
}
if err := pprofServer.Close(); err != nil {
t.Fatalf("Expected no error when closing disabled pprof server, got: %v", err)
}
}