github.heygears.com/openimsdk/tools@v0.0.49/log/file-rotatelogs/internal/fileutil/fileutil_test.go (about) 1 package fileutil_test 2 3 import ( 4 "fmt" 5 "github.com/openimsdk/tools/log/file-rotatelogs/internal/fileutil" 6 "testing" 7 "time" 8 9 "github.com/jonboulle/clockwork" 10 "github.com/lestrrat-go/strftime" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestGenerateFn(t *testing.T) { 15 // Mock time 16 ts := []time.Time{ 17 {}, 18 (time.Time{}).Add(24 * time.Hour), 19 } 20 21 for _, xt := range ts { 22 pattern, err := strftime.New("/path/to/%Y/%m/%d") 23 if !assert.NoError(t, err, `strftime.New should succeed`) { 24 return 25 } 26 clock := clockwork.NewFakeClockAt(xt) 27 fn := fileutil.GenerateFn(pattern, clock, 24*time.Hour) 28 expected := fmt.Sprintf("/path/to/%04d/%02d/%02d", 29 xt.Year(), 30 xt.Month(), 31 xt.Day(), 32 ) 33 34 if !assert.Equal(t, expected, fn) { 35 return 36 } 37 } 38 }