Files
go-zero/core/proc/goroutines_test.go

42 lines
798 B
Go
Raw Normal View History

2023-06-12 01:22:20 +08:00
//go:build linux || darwin
2020-09-29 14:30:22 +08:00
package proc
import (
2023-06-12 01:22:20 +08:00
"errors"
"os"
2020-09-29 14:30:22 +08:00
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/logx/logtest"
2020-09-29 14:30:22 +08:00
)
func TestDumpGoroutines(t *testing.T) {
2023-06-12 01:22:20 +08:00
t.Run("real file", func(t *testing.T) {
buf := logtest.NewCollector(t)
dumpGoroutines(fileCreator{})
assert.True(t, strings.Contains(buf.String(), ".dump"))
})
t.Run("fake file", func(t *testing.T) {
const msg = "any message"
buf := logtest.NewCollector(t)
err := errors.New(msg)
dumpGoroutines(fakeCreator{
file: &os.File{},
err: err,
})
assert.True(t, strings.Contains(buf.String(), msg))
})
}
type fakeCreator struct {
file *os.File
err error
}
2024-03-08 22:35:17 +08:00
func (fc fakeCreator) Create(_ string) (file *os.File, err error) {
2023-06-12 01:22:20 +08:00
return fc.file, fc.err
2020-09-29 14:30:22 +08:00
}