github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/rotate/fn_test.go (about) 1 package rotate 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestMatchExpiredFiles(t *testing.T) { 10 assert.Equal(t, "somepath/????????*.log", matchExpiredFiles("somepath/yyyyMMdd.log", "")) 11 assert.Equal(t, "somepath/????????*.log.gz", matchExpiredFiles("somepath/yyyyMMdd.log", ".gz")) 12 } 13 14 func TestSetFileIndex(t *testing.T) { 15 assert.Equal(t, "abc_00002.txt", SetFileIndex("abc_00001.txt", 2)) 16 assert.Equal(t, "abc_00002.txt", SetFileIndex("abc.txt", 2)) 17 } 18 19 func TestGetFileIndex(t *testing.T) { 20 assert.Equal(t, 123, GetFileIndex("abc_00123.txt")) 21 assert.Equal(t, 123, GetFileIndex("abc_00123.123")) 22 assert.Equal(t, -1, GetFileIndex("abc.123")) 23 } 24 25 func TestGzip(t *testing.T) { 26 writer := NewFileWriter("/tmp/xx-yyyyMMdd.log.gz", 0, true, 1) 27 writer.Write([]byte("hello world!")) 28 writer.Close() 29 }