github.com/blong14/gache@v0.0.0-20240124023949-89416fd8bbfa/internal/io/file/csv_test.go (about) 1 package file_test 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 gfile "github.com/blong14/gache/internal/io/file" 8 ) 9 10 func TestReadCSV(t *testing.T) { 11 t.Parallel() 12 scanner := gfile.ScanCSV(filepath.Join("testdata", "i.csv")) 13 scanner.Init() 14 var count int 15 for scanner.Scan() { 16 count += len(scanner.Rows()) 17 } 18 if count == 0 { 19 t.Error("value is nil") 20 } 21 t.Log(count) 22 } 23 24 func BenchmarkScanCSV(b *testing.B) { 25 b.ReportAllocs() 26 out := make([][]string, 0) 27 for i := 0; i < b.N; i++ { 28 reader := gfile.ScanCSV(filepath.Join("testdata", "i.csv")) 29 reader.Init() 30 for reader.Scan() { 31 out = append(out, reader.Rows()...) 32 } 33 } 34 b.ReportMetric(float64(len(out)), "items") 35 }