82 lines
2 KiB
Go
82 lines
2 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadDefault(t *testing.T) {
|
|
cfg := LoadDefault()
|
|
if cfg.Model != "gpt-4o" {
|
|
t.Errorf("expected default model 'gpt-4o', got %q", cfg.Model)
|
|
}
|
|
if cfg.Provider.Type != "openai" {
|
|
t.Errorf("expected default provider 'openai', got %q", cfg.Provider.Type)
|
|
}
|
|
}
|
|
|
|
func TestYAMLLoader_NoFile(t *testing.T) {
|
|
loader := NewYAMLLoader()
|
|
ctx := context.Background()
|
|
cfg, err := loader.Load(ctx, "/tmp/nonexistent_workdir_12345")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if cfg.Model != "gpt-4o" {
|
|
t.Errorf("expected default model, got %q", cfg.Model)
|
|
}
|
|
}
|
|
|
|
func TestYAMLLoader_WithFile(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
yaml := `
|
|
provider:
|
|
type: anthropic
|
|
model: claude-sonnet-4.5
|
|
api_key: test-key
|
|
`
|
|
if err := os.WriteFile(filepath.Join(tmpDir, "rony.yaml"), []byte(yaml), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
loader := NewYAMLLoader()
|
|
ctx := context.Background()
|
|
cfg, err := loader.Load(ctx, tmpDir)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if cfg.Provider.Type != "anthropic" {
|
|
t.Errorf("expected provider 'anthropic', got %q", cfg.Provider.Type)
|
|
}
|
|
if cfg.Provider.Model != "claude-sonnet-4.5" {
|
|
t.Errorf("expected model 'claude-sonnet-4.5', got %q", cfg.Provider.Model)
|
|
}
|
|
if cfg.Provider.APIKey != "test-key" {
|
|
t.Errorf("expected api_key 'test-key', got %q", cfg.Provider.APIKey)
|
|
}
|
|
}
|
|
|
|
func TestYAMLLoader_PreservesDefaults(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
yaml := `
|
|
provider:
|
|
type: openai
|
|
model: gpt-4o-mini
|
|
`
|
|
if err := os.WriteFile(filepath.Join(tmpDir, "rony.yaml"), []byte(yaml), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
loader := NewYAMLLoader()
|
|
ctx := context.Background()
|
|
cfg, err := loader.Load(ctx, tmpDir)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
// Should still have default logging config
|
|
if cfg.Logging.Level != "info" {
|
|
t.Errorf("expected default logging level 'info', got %q", cfg.Logging.Level)
|
|
}
|
|
}
|