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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package gallery
import (
"context"
"path/filepath"
"testing"
"time"
"github.com/RanXom/galleryd/internal/metadata"
"github.com/RanXom/galleryd/internal/scanner"
)
func TestBuilder(t *testing.T) {
reader := metadata.New()
builder := New(reader)
t.Run("builds gallery photos", func(t *testing.T) {
files := []scanner.File{
{
Path: filepath.Join("..", "testfixtures", "Canon_40D.jpg"),
Root: "testfixtures",
RelativePath: "Canon_40D.jpg",
ModTime: time.Now(),
},
}
photos, err := builder.Build(context.Background(), files)
if err != nil {
t.Fatalf("build gallery: %v", err)
}
if len(photos) != 1 {
t.Fatalf("expected 1 photo, got %d", len(photos))
}
})
t.Run("generates deterministic ids", func(t *testing.T) {
file := scanner.File{
Path: filepath.Join("..", "testfixtures", "Canon_40D.jpg"),
Root: "photos",
RelativePath: "Canon_40D.jpg",
ModTime: time.Now(),
}
first, err := builder.Build(context.Background(), []scanner.File{file})
if err != nil {
t.Fatal(err)
}
second, err := builder.Build(context.Background(), []scanner.File{file})
if err != nil {
t.Fatal(err)
}
if first[0].ID != second[0].ID {
t.Fatal("photo IDs should be deterministic")
}
})
t.Run("respects context cancellation", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := builder.Build(ctx, nil)
if err == nil {
t.Fatal("expected context cancellation error")
}
})
}
|