Refactored, added comprehensive testing.
All checks were successful
Release / release (push) Successful in 3m17s

This commit is contained in:
Jay
2025-10-26 23:23:43 -04:00
parent ec32b75267
commit 1936f055e2
61 changed files with 4678 additions and 769 deletions

74
config/validate_test.go Normal file
View File

@@ -0,0 +1,74 @@
package config
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestValidateConfig(t *testing.T) {
tests := []struct {
name string
cfg ConfigData
wantErr bool
errMsg string
}{
{
name: "valid config",
cfg: ConfigData{
Protocol: ProtocolOpenAI,
URL: "https://api.openai.com",
Model: "gpt-4",
FallbackModels: []string{"gpt-3.5"},
APIKey: "sk-test123",
},
wantErr: false,
},
{
name: "missing api key",
cfg: ConfigData{
Protocol: ProtocolOpenAI,
URL: "https://api.openai.com",
Model: "gpt-4",
FallbackModels: []string{"gpt-3.5"},
APIKey: "",
},
wantErr: true,
errMsg: "API key required",
},
{
name: "invalid protocol",
cfg: ConfigData{
Protocol: APIProtocol(99),
URL: "https://api.openai.com",
Model: "gpt-4",
FallbackModels: []string{"gpt-3.5"},
APIKey: "sk-test123",
},
wantErr: true,
errMsg: "invalid protocol",
},
{
name: "ollama protocol valid",
cfg: ConfigData{
Protocol: ProtocolOllama,
URL: "http://localhost:11434",
Model: "llama3",
FallbackModels: []string{},
APIKey: "not-used-but-required",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateConfig(tt.cfg)
if tt.wantErr {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.errMsg)
} else {
assert.NoError(t, err)
}
})
}
}