1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package scanner
import (
"context"
"path/filepath"
"testing"
)
func TestScan(t *testing.T) {
root := filepath.Join("testdata", "gallery")
s := New([]string{root})
files, err := s.Scan(context.Background())
if err != nil {
t.Fatalf("Scan failed: %v", err)
}
t.Run("Find supported images", func(t *testing.T) {
expected := map[string]struct{}{
"cat.jpg": {},
"dog.png": {},
"beach.webp": {},
}
for _, file := range files {
delete(expected, filepath.Base(file.Path))
}
if len(expected) != 0 {
t.Fatalf("Missing files: %v", expected)
}
})
t.Run("Ignore unsupported files", func(t *testing.T) {
for _, file := range files {
switch filepath.Base(file.Path) {
case "readme.txt", "jeffsfiles.pdf":
t.Fatalf("Scanner returned unsupported files %q", file.Path)
}
}
})
t.Run("Skip hidden directories", func(t *testing.T) {
for _, file := range files {
if filepath.Base(file.Path) == "nuclearlaunchcode.txt" {
t.Fatal("Hidden file entered the scanner")
}
}
})
}
|