aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 12:50:29 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 12:50:29 +0530
commit0447a00e3d3b9c4fd8971b5ffebc323060306b98 (patch)
tree815fbb8bda2f1365ae24e393ae57a5c0e7dc7021
parentfe720c980e714cb664902115bf842558e0f7cc95 (diff)
downloadgalleryd-0447a00e3d3b9c4fd8971b5ffebc323060306b98.tar.xz
galleryd-0447a00e3d3b9c4fd8971b5ffebc323060306b98.zip
test(gallery): add gallery behavior tests
-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")
+ }
+ })
+}