desktop/scan_test.go

48 lines
814 B
Go
Raw Permalink Normal View History

2019-07-15 02:27:02 +00:00
package desktop
import (
2020-01-28 00:18:44 +00:00
"fmt"
"os"
"path"
2019-07-15 02:27:02 +00:00
"testing"
)
func TestScan(t *testing.T) {
2020-01-28 00:18:44 +00:00
dirs, err := getTestScanDirs()
if err != nil {
t.Fatalf("failed to get test scan dirs: %s", err)
}
2019-07-15 02:27:02 +00:00
2020-01-28 00:18:44 +00:00
entries, err := Scan(dirs)
2019-07-15 02:27:02 +00:00
if err != nil {
2020-01-28 00:18:44 +00:00
t.Fatalf("failed to scan %s: %s", dirs[0], err)
2019-07-15 02:27:02 +00:00
}
2020-01-28 00:18:44 +00:00
_ = entries
2019-07-15 02:27:02 +00:00
}
func BenchmarkScan(b *testing.B) {
2020-01-28 00:18:44 +00:00
dirs, err := getTestScanDirs()
if err != nil {
b.Fatalf("failed to get test scan dirs: %s", err)
}
2019-07-15 02:27:02 +00:00
2020-01-28 00:18:44 +00:00
var entries [][]*Entry
2019-07-15 02:27:02 +00:00
b.ResetTimer()
for i := 0; i < b.N; i++ {
2020-01-28 00:18:44 +00:00
entries, err = Scan(dirs)
2019-07-15 02:27:02 +00:00
if err != nil {
b.Fatal(err)
}
}
2020-01-28 00:18:44 +00:00
_ = entries
}
func getTestScanDirs() ([]string, error) {
wd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("failed to get current working directory: %s", err)
}
return []string{path.Join(wd, "test")}, nil
2019-07-15 02:27:02 +00:00
}