github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/rotation/archive_by_move_test.go (about) 1 package rotation 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/test" 6 "github.com/v2pro/plz/countlog" 7 "os" 8 "io/ioutil" 9 "github.com/v2pro/plz/test/must" 10 "github.com/v2pro/plz/clock" 11 "time" 12 ) 13 14 func Test_ArchiveByMove(t *testing.T) { 15 t.Run("", test.Case(func(ctx *countlog.Context) { 16 os.Remove("/tmp/test.log") 17 ioutil.WriteFile("/tmp/test.log", []byte("hello"), 0644) 18 archiver := &ArchiveByMove{ 19 NamingStrategy: &NameByTime{ 20 Directory: "/tmp", 21 Pattern: "test-2006.log", 22 }, 23 } 24 defer clock.ResetNow() 25 clock.Now = func() time.Time { 26 return time.Unix(0, 0) 27 } 28 must.Call(archiver.Archive, "/tmp/test.log") 29 content := must.Call(ioutil.ReadFile, "/tmp/test-1970.log")[0] 30 must.Equal([]byte("hello"), content) 31 })) 32 }