summaryrefslogtreecommitdiff
path: root/internal/cli
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-06 11:34:20 +0300
committerPaul Buetow <paul@buetow.org>2026-04-06 11:34:20 +0300
commit7193ec765f0b51093a203f8f3d00e69008be1cce (patch)
tree8d7df4403b55602c12f3bc85276b55ff705849c5 /internal/cli
parent2d905b109cd2ea3763b3c39f54dbb0f86b4b19ba (diff)
test: add missing unit tests for Veo video feature (task 016)
- internal/video/veo_test.go: add pageNumFromPath table test, loadGalleryImage multiple-matches edge case, saveMP4 fallback name, and NewVeoGenerator success path with mock client injection - internal/cli/prompts_test.go: add parseSelection edge cases — zero max with "all", page number exceeding max, and whitespace-only input - internal/cli/video_runner_test.go: new file covering GenerateSelectedVideos for empty/nil paths (early return) and empty/whitespace API key (error path) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/cli')
-rw-r--r--internal/cli/prompts_test.go45
-rw-r--r--internal/cli/video_runner_test.go44
2 files changed, 89 insertions, 0 deletions
diff --git a/internal/cli/prompts_test.go b/internal/cli/prompts_test.go
index 053f0b4..7eb6344 100644
--- a/internal/cli/prompts_test.go
+++ b/internal/cli/prompts_test.go
@@ -266,3 +266,48 @@ func TestFilterPathsByPages_Empty(t *testing.T) {
t.Errorf("expected empty result, got %v", got)
}
}
+
+// ---------------------------------------------------------------------------
+// parseSelection — additional edge cases
+// ---------------------------------------------------------------------------
+
+// TestParseSelection_AllWithZeroMax verifies that "all" with a zero max
+// returns an empty (but non-nil) slice, since there are no available pages.
+func TestParseSelection_AllWithZeroMax(t *testing.T) {
+ got, err := parseSelection("all", 0)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if len(got) != 0 {
+ t.Errorf("parseSelection(\"all\", 0): expected empty slice, got %v", got)
+ }
+}
+
+// TestParseSelection_PageExceedsMax verifies that a page number larger than
+// max is accepted without error — the caller filters against real files.
+func TestParseSelection_PageExceedsMax(t *testing.T) {
+ got, err := parseSelection("99", 5)
+ if err != nil {
+ t.Fatalf("unexpected error for page > max: %v", err)
+ }
+ want := []int{99}
+ if len(got) != 1 || got[0] != want[0] {
+ t.Errorf("parseSelection(\"99\", 5) = %v, want %v", got, want)
+ }
+}
+
+// TestParseSelection_OnlyWhitespace verifies that a purely whitespace input
+// (after trimming) is treated as "all" via the caller, but parseSelection
+// itself should not receive it — nonetheless it should not panic.
+func TestParseSelection_EmptyAfterTrim(t *testing.T) {
+ // Empty string after trimming: no tokens, so result is empty, no error.
+ got, err := parseSelection(" ", 5)
+ if err != nil {
+ t.Fatalf("unexpected error for all-whitespace input: %v", err)
+ }
+ // "all" is the keyword path — plain whitespace is NOT "all", so the
+ // comma-split path runs and produces an empty result (all tokens are "").
+ if len(got) != 0 {
+ t.Errorf("parseSelection(\" \", 5): expected empty slice, got %v", got)
+ }
+}
diff --git a/internal/cli/video_runner_test.go b/internal/cli/video_runner_test.go
new file mode 100644
index 0000000..1fd201d
--- /dev/null
+++ b/internal/cli/video_runner_test.go
@@ -0,0 +1,44 @@
+package cli
+
+import (
+ "testing"
+)
+
+// TestGenerateSelectedVideos_EmptyPaths verifies that GenerateSelectedVideos
+// returns nil immediately when no paths are provided, without attempting any
+// API calls.
+func TestGenerateSelectedVideos_EmptyPaths(t *testing.T) {
+ err := GenerateSelectedVideos("any-api-key", []string{})
+ if err != nil {
+ t.Fatalf("expected nil for empty paths, got: %v", err)
+ }
+}
+
+// TestGenerateSelectedVideos_NilPaths verifies that GenerateSelectedVideos
+// handles a nil slice the same way as an empty slice.
+func TestGenerateSelectedVideos_NilPaths(t *testing.T) {
+ err := GenerateSelectedVideos("any-api-key", nil)
+ if err != nil {
+ t.Fatalf("expected nil for nil paths, got: %v", err)
+ }
+}
+
+// TestGenerateSelectedVideos_EmptyAPIKey verifies that GenerateSelectedVideos
+// returns an error when a non-empty path list is provided but the API key is
+// empty. The error originates from video.NewVeoGenerator, so we just check
+// that some error is returned without making any real API calls.
+func TestGenerateSelectedVideos_EmptyAPIKey(t *testing.T) {
+ err := GenerateSelectedVideos("", []string{"/some/word_gallery_1.png"})
+ if err == nil {
+ t.Fatal("expected error for empty API key with non-empty paths, got nil")
+ }
+}
+
+// TestGenerateSelectedVideos_WhitespaceAPIKey verifies that a whitespace-only
+// API key is treated equivalently to an empty key when paths are supplied.
+func TestGenerateSelectedVideos_WhitespaceAPIKey(t *testing.T) {
+ err := GenerateSelectedVideos(" ", []string{"/some/word_gallery_1.png"})
+ if err == nil {
+ t.Fatal("expected error for whitespace API key with non-empty paths, got nil")
+ }
+}