github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/file/bounds_test.go (about) 1 package file 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 ) 8 9 func Test_Latest(t *testing.T) { 10 tmpPath := "./" 11 files := []string{ 12 "000000000-000000000.bin", 13 "zzzzzzzzz-555555555.bin", 14 "110100101-110100101.bin", 15 } 16 for _, file := range files { 17 Touch(file) 18 } 19 20 latest, err := LatestFileInFolder(tmpPath) 21 if err != nil { 22 t.Error(err) 23 } 24 25 earliest, err := EarliestFileInFolder(tmpPath) 26 if err != nil { 27 t.Error(err) 28 } 29 30 for _, file := range files { 31 Remove(file) 32 } 33 34 if err != nil { 35 t.Error("error fetching latest file") 36 } 37 38 if !strings.Contains(earliest, files[0]) { 39 msg := fmt.Sprintf("Expected '%s', Got '%s'", files[0], earliest) 40 t.Error(msg) 41 } 42 43 if !strings.Contains(latest, files[1]) { 44 msg := fmt.Sprintf("Expected '%s', Got '%s'", files[1], latest) 45 t.Error(msg) 46 } 47 }