From 980aa06e29f5a357c75280c66573db9ae99d1b55 Mon Sep 17 00:00:00 2001 From: Inhere Date: Thu, 2 May 2024 10:36:24 +0800 Subject: [PATCH] :white_check_mark: test: add a test case for issues #137 --- issues_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/issues_test.go b/issues_test.go index 9726fb8..4bb4c0d 100644 --- a/issues_test.go +++ b/issues_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/gookit/goutil/byteutil" + "github.com/gookit/goutil/fsutil" "github.com/gookit/goutil/testutil/assert" "github.com/gookit/goutil/timex" "github.com/gookit/slog" @@ -185,3 +186,23 @@ func TestIssues_121(t *testing.T) { l.MustClose() } + +// https://github.com/gookit/slog/issues/137 +// 按日期滚动 如果当天时间节点的日志文件已存在 不会append 会直接替换 #137 +func TestIssues_137(t *testing.T) { + logFile := "testdata/issue137_case.log" + fsutil.MustSave(logFile, "hello, this is a log file content\n") + + l := slog.NewWithHandlers(handler.MustFileHandler(logFile)) + + // add logs + for i := 0; i < 5; i++ { + l.Infof("hi, this is a example information ... message text. log index=%d", i) + } + + l.MustClose() + // read file content + content := fsutil.ReadString(logFile) + assert.StrContains(t, content, "this is a log file content") + assert.StrContains(t, content, "log index=4") +}