github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/rotation/name_by_index_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 "github.com/v2pro/plz/test/must" 9 "io/ioutil" 10 ) 11 12 func Test_NameByIndex(t *testing.T) { 13 t.Run("directory not exists", test.Case(func(ctx *countlog.Context) { 14 os.RemoveAll("/tmp/testlog") 15 naming := &NameByIndex{ 16 Directory: "/tmp/testlog", 17 Pattern: "test-{i}.log", 18 StartIndex: 1, 19 } 20 must.Equal([]string{}, must.Call(naming.ListFiles)[0]) 21 })) 22 t.Run("directory with indexed and not indexed files", test.Case(func(ctx *countlog.Context) { 23 os.RemoveAll("/tmp/testlog") 24 os.MkdirAll("/tmp/testlog", 0755) 25 ioutil.WriteFile("/tmp/testlog/test-2.log", []byte{}, 0644) 26 ioutil.WriteFile("/tmp/testlog/test-a.log", []byte{}, 0644) 27 naming := &NameByIndex{ 28 Directory: "/tmp/testlog", 29 Pattern: "test-%d.log", 30 StartIndex: 1, 31 } 32 must.Equal([]string{ 33 "/tmp/testlog/test-2.log", 34 }, must.Call(naming.ListFiles)[0]) 35 })) 36 }