Files
website/app/internal/gallery/gallery_test.go
jimmy 509e7ccb43 Add Technical Kiwi website with Go, templ, and HTMX.
Single-page site with gallery by album and event, contact form over SMTP,
Docker dev/prod setup, and on-server image derivatives. Gallery photos stay
local (app/images/ is gitignored).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 23:57:59 +12:00

58 lines
1.4 KiB
Go

package gallery
import (
"os"
"path/filepath"
"testing"
)
func TestAlbumFromRel(t *testing.T) {
if albumFromRel("portal/IMG_20241012_115041.jpg") != "portal" {
t.Fatal("expected portal album")
}
if albumFromRel("IMG_20241012_115041.jpg") != "" {
t.Fatal("expected empty album for root file")
}
}
func TestSafeRelPath(t *testing.T) {
if !safeRelPath("portal/foo.jpg") {
t.Fatal("valid path rejected")
}
if safeRelPath("../etc/passwd") {
t.Fatal("traversal allowed")
}
}
func TestList_subfolders(t *testing.T) {
dir := t.TempDir()
album := filepath.Join(dir, "portal")
if err := os.MkdirAll(album, 0o755); err != nil {
t.Fatal(err)
}
name := "IMG_20240101_120000.jpg"
if err := os.WriteFile(filepath.Join(album, name), []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
images, err := List(dir)
if err != nil {
t.Fatal(err)
}
if len(images) != 1 || images[0].Album != "portal" || images[0].RelPath != "portal/"+name {
t.Fatalf("got %+v", images)
}
}
func TestCollections_nested(t *testing.T) {
images := []Image{
{Album: "templeoftechno", CollectionKey: "anniversary", Collection: "Anniversary"},
{Album: "templeoftechno", CollectionKey: "groovatory", Collection: "Groovatory"},
{Album: "portal", CollectionKey: "x", Collection: "X"},
}
keys := Collections(images, "templeoftechno")
if len(keys) != 2 {
t.Fatalf("got %v", keys)
}
}