summaryrefslogtreecommitdiff
path: root/internal/cli/command_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-01 15:41:42 +0300
committerPaul Buetow <paul@buetow.org>2026-04-01 15:41:42 +0300
commit8e7063e78f5067f79d2a1a9e2b0fc2fde86d1f6e (patch)
treeeef470c2663671e1a8fce8273677fb844055e1df /internal/cli/command_test.go
parent3967d8dca4ebe87e43d243c5bbffe34ca0dcab51 (diff)
z7: keep Nano Banana CLI additive
Diffstat (limited to 'internal/cli/command_test.go')
-rw-r--r--internal/cli/command_test.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/internal/cli/command_test.go b/internal/cli/command_test.go
index ab21c49..1ebff95 100644
--- a/internal/cli/command_test.go
+++ b/internal/cli/command_test.go
@@ -100,8 +100,8 @@ func TestSetupFlags(t *testing.T) {
if imageAPIFlag == nil {
t.Fatal("image-api flag not found")
}
- if imageAPIFlag.DefValue != "nanobanana" {
- t.Errorf("Expected default image-api to be nanobanana, got %s", imageAPIFlag.DefValue)
+ if imageAPIFlag.DefValue != "openai" {
+ t.Errorf("Expected default image-api to be openai, got %s", imageAPIFlag.DefValue)
}
nanoBananaModelFlag := cmd.Flags().Lookup("nanobanana-model")
@@ -275,24 +275,35 @@ func TestGetGoogleAPIKey(t *testing.T) {
name string
envKey string
configKey string
+ legacyKey string
expected string
}{
{
name: "from environment",
envKey: "env-google-key",
configKey: "config-google-key",
+ legacyKey: "legacy-google-key",
expected: "env-google-key",
},
{
name: "from config when no env",
envKey: "",
configKey: "config-google-key",
+ legacyKey: "legacy-google-key",
expected: "config-google-key",
},
{
+ name: "falls back to legacy config key",
+ envKey: "",
+ configKey: "",
+ legacyKey: "legacy-google-key",
+ expected: "legacy-google-key",
+ },
+ {
name: "empty when neither set",
envKey: "",
configKey: "",
+ legacyKey: "",
expected: "",
},
}
@@ -319,6 +330,9 @@ func TestGetGoogleAPIKey(t *testing.T) {
if tt.configKey != "" {
viper.Set("image.google_api_key", tt.configKey)
}
+ if tt.legacyKey != "" {
+ viper.Set("google.api_key", tt.legacyKey)
+ }
got := GetGoogleAPIKey()
if got != tt.expected {
@@ -328,6 +342,26 @@ func TestGetGoogleAPIKey(t *testing.T) {
}
}
+func TestGetGoogleAPIKey_PrefersImageConfigOverLegacyConfig(t *testing.T) {
+ originalConfig := viper.New()
+ *originalConfig = *viper.GetViper()
+ defer func() {
+ *viper.GetViper() = *originalConfig
+ }()
+
+ viper.Reset()
+ if err := os.Unsetenv("GOOGLE_API_KEY"); err != nil {
+ t.Fatalf("Failed to unset GOOGLE_API_KEY: %v", err)
+ }
+
+ viper.Set("image.google_api_key", "new-google-key")
+ viper.Set("google.api_key", "legacy-google-key")
+
+ if got := GetGoogleAPIKey(); got != "new-google-key" {
+ t.Fatalf("GetGoogleAPIKey() = %v, want %v", got, "new-google-key")
+ }
+}
+
func TestBindFlagsToViper(t *testing.T) {
// Save original viper state
originalConfig := viper.New()
@@ -382,4 +416,7 @@ func TestBindFlagsToViper(t *testing.T) {
if viper.GetString("image.nanobanana_text_model") != "gemini-2.5-flash" {
t.Errorf("Expected image.nanobanana_text_model to be gemini-2.5-flash, got %s", viper.GetString("image.nanobanana_text_model"))
}
+ if viper.GetString("image.provider") != "openai" {
+ t.Errorf("Expected image.provider to be openai by default, got %s", viper.GetString("image.provider"))
+ }
}