mirror of
https://github.com/usememos/memos.git
synced 2025-12-17 06:12:42 +08:00
test: update AI plugin tests for new configuration structure
- Add Enabled field to all Config test objects - Update timeout expectations to reflect 10s default - Change API key test expectation to support optional keys for local services - Fix all LoadConfigFromEnv test cases for new field structure - Ensure all Chat and Client tests use properly configured objects Signed-off-by: ChaoLiu <chaoliu719@gmail.com>
This commit is contained in:
parent
9db3dcf0a2
commit
9cfdacc387
1 changed files with 29 additions and 11 deletions
|
|
@ -24,18 +24,22 @@ func TestLoadConfigFromEnv(t *testing.T) {
|
||||||
"AI_MODEL": "gpt-4o",
|
"AI_MODEL": "gpt-4o",
|
||||||
},
|
},
|
||||||
expected: &Config{
|
expected: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
TimeoutSeconds: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no environment variables set",
|
name: "no environment variables set",
|
||||||
envVars: map[string]string{},
|
envVars: map[string]string{},
|
||||||
expected: &Config{
|
expected: &Config{
|
||||||
|
Enabled: false,
|
||||||
BaseURL: "",
|
BaseURL: "",
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
Model: "",
|
Model: "",
|
||||||
|
TimeoutSeconds: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -45,9 +49,11 @@ func TestLoadConfigFromEnv(t *testing.T) {
|
||||||
"AI_API_KEY": "sk-custom123",
|
"AI_API_KEY": "sk-custom123",
|
||||||
},
|
},
|
||||||
expected: &Config{
|
expected: &Config{
|
||||||
|
Enabled: false,
|
||||||
BaseURL: "https://custom.api.com/v1",
|
BaseURL: "https://custom.api.com/v1",
|
||||||
APIKey: "sk-custom123",
|
APIKey: "sk-custom123",
|
||||||
Model: "",
|
Model: "",
|
||||||
|
TimeoutSeconds: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +106,7 @@ func TestConfig_IsConfigured(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "fully configured",
|
name: "fully configured",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -109,6 +116,7 @@ func TestConfig_IsConfigured(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "missing base URL",
|
name: "missing base URL",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "",
|
BaseURL: "",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -118,15 +126,17 @@ func TestConfig_IsConfigured(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "missing API key",
|
name: "missing API key",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing model",
|
name: "missing model",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "",
|
Model: "",
|
||||||
|
|
@ -136,6 +146,7 @@ func TestConfig_IsConfigured(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "all fields empty",
|
name: "all fields empty",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: false,
|
||||||
BaseURL: "",
|
BaseURL: "",
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
Model: "",
|
Model: "",
|
||||||
|
|
@ -161,6 +172,7 @@ func TestNewClient(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "standard OpenAI configuration",
|
name: "standard OpenAI configuration",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -170,6 +182,7 @@ func TestNewClient(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "custom endpoint configuration",
|
name: "custom endpoint configuration",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://custom.api.com/v1",
|
BaseURL: "https://custom.api.com/v1",
|
||||||
APIKey: "sk-custom123",
|
APIKey: "sk-custom123",
|
||||||
Model: "gpt-3.5-turbo",
|
Model: "gpt-3.5-turbo",
|
||||||
|
|
@ -179,6 +192,7 @@ func TestNewClient(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "incomplete configuration",
|
name: "incomplete configuration",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: false,
|
||||||
BaseURL: "",
|
BaseURL: "",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -193,11 +207,12 @@ func TestNewClient(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "missing API key",
|
name: "missing API key",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
},
|
},
|
||||||
expectErr: true,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,6 +236,7 @@ func TestNewClient(t *testing.T) {
|
||||||
func TestClient_Chat_RequestDefaults(t *testing.T) {
|
func TestClient_Chat_RequestDefaults(t *testing.T) {
|
||||||
// This test verifies that default values are properly set
|
// This test verifies that default values are properly set
|
||||||
config := &Config{
|
config := &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -320,6 +336,7 @@ func TestClient_Chat_Integration(t *testing.T) {
|
||||||
|
|
||||||
func TestClient_Chat_Validation(t *testing.T) {
|
func TestClient_Chat_Validation(t *testing.T) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
@ -406,6 +423,7 @@ func TestClient_Chat_Validation(t *testing.T) {
|
||||||
|
|
||||||
func TestClient_Chat_ErrorTypes(t *testing.T) {
|
func TestClient_Chat_ErrorTypes(t *testing.T) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
|
Enabled: true,
|
||||||
BaseURL: "https://api.openai.com/v1",
|
BaseURL: "https://api.openai.com/v1",
|
||||||
APIKey: "sk-test123",
|
APIKey: "sk-test123",
|
||||||
Model: "gpt-4o",
|
Model: "gpt-4o",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue