aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/gallery/builder_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/internal/gallery/builder_test.go b/internal/gallery/builder_test.go
new file mode 100644
index 0000000..88b4533
--- /dev/null
+++ b/internal/gallery/builder_test.go
@@ -0,0 +1,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("..", "metadata", "testdata", "Canon_40D.jpg"),
+ Root: "testdata",
+ 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("..", "metadata", "testdata", "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")
+ }
+ })
+}