diff options
Diffstat (limited to 'internal/hexaicli')
| -rw-r--r-- | internal/hexaicli/run_test.go | 12 | ||||
| -rw-r--r-- | internal/hexaicli/testhelpers_test.go | 10 |
2 files changed, 20 insertions, 2 deletions
diff --git a/internal/hexaicli/run_test.go b/internal/hexaicli/run_test.go index dfde068..991965e 100644 --- a/internal/hexaicli/run_test.go +++ b/internal/hexaicli/run_test.go @@ -125,12 +125,20 @@ func TestRunWithClient_ErrorPrint(t *testing.T) { func TestRun_OpenAI_NoKey_ShowsError(t *testing.T) { dir := testingTempDir(t) - // write config with provider=openai - writeTOML(t, filepath.Join(dir, "hexai", "config.toml"), map[string]string{"provider": "openai", "openai_model": "gpt-x"}) + // write config with provider=openai using sectioned tables + configPath := filepath.Join(dir, "hexai", "config.toml") + writeConfigString(t, configPath, ` +[provider] +name = "openai" + +[openai] +model = "gpt-x" +`) t.Setenv("XDG_CONFIG_HOME", dir) // Ensure no OpenAI API key is present in environment t.Setenv("HEXAI_OPENAI_API_KEY", "") t.Setenv("OPENAI_API_KEY", "") + t.Setenv("HEXAI_PROVIDER", "") var out, errb bytes.Buffer // Run expects parsed flags; here args irrelevant err := Run(context.Background(), []string{"hello"}, strings.NewReader(""), &out, &errb) diff --git a/internal/hexaicli/testhelpers_test.go b/internal/hexaicli/testhelpers_test.go index 93f1e3d..4cc04f7 100644 --- a/internal/hexaicli/testhelpers_test.go +++ b/internal/hexaicli/testhelpers_test.go @@ -79,4 +79,14 @@ func writeTOML(t *testing.T, path string, m map[string]string) { } } +func writeConfigString(t *testing.T, path string, contents string) { + t.Helper() + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatalf("mkdir: %v", err) + } + if err := os.WriteFile(path, []byte(contents), 0o644); err != nil { + t.Fatalf("write: %v", err) + } +} + func testingTempDir(t *testing.T) string { t.Helper(); return t.TempDir() } |
