|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zeromicro/go-zero/core/fs"
|
|
|
|
"github.com/zeromicro/go-zero/core/fs"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestDailyRotateRuleMarkRotated(t *testing.T) {
|
|
|
|
func TestDailyRotateRuleMarkRotated(t *testing.T) {
|
|
|
@ -232,6 +233,23 @@ func TestRotateLoggerWithSizeLimitRotateRuleMayCompressFileTrue(t *testing.T) {
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestRotateLoggerWithSizeLimitRotateRuleMayCompressFileFailed(t *testing.T) {
|
|
|
|
|
|
|
|
old := os.Stdout
|
|
|
|
|
|
|
|
os.Stdout = os.NewFile(0, os.DevNull)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
os.Stdout = old
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filename := stringx.RandId()
|
|
|
|
|
|
|
|
logger, err := NewLogger(filename, new(SizeLimitRotateRule), true)
|
|
|
|
|
|
|
|
defer os.Remove(filename)
|
|
|
|
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
|
|
|
logger.maybeCompressFile(stringx.RandId())
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestRotateLoggerWithSizeLimitRotateRuleRotate(t *testing.T) {
|
|
|
|
func TestRotateLoggerWithSizeLimitRotateRuleRotate(t *testing.T) {
|
|
|
|
filename, err := fs.TempFilenameWithText("foo")
|
|
|
|
filename, err := fs.TempFilenameWithText("foo")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|