aboutsummaryrefslogtreecommitdiff
path: root/internal/scanner/scanner_test.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 01:11:51 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 01:11:51 +0530
commitacb7160bb7dd885ae45f762d967ddfd4be6a3d23 (patch)
tree8d2c929c47a596de6d61201811a947f3dd6a8c8f /internal/scanner/scanner_test.go
parent2c260b715802857e3026e6789ec32a7dd9699c80 (diff)
downloadgalleryd-acb7160bb7dd885ae45f762d967ddfd4be6a3d23.tar.xz
galleryd-acb7160bb7dd885ae45f762d967ddfd4be6a3d23.zip
test(scanner): add scanner behavior tests
Diffstat (limited to 'internal/scanner/scanner_test.go')
-rw-r--r--internal/scanner/scanner_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/scanner/scanner_test.go b/internal/scanner/scanner_test.go
new file mode 100644
index 0000000..f13384a
--- /dev/null
+++ b/internal/scanner/scanner_test.go
@@ -0,0 +1,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")
+ }
+ }
+ })
+}