Files
example-eino/adk/internal/config/config_test.go
T
zhaoyupeng.elqbandTRAE CLI 81deca8c8e feat: initialize Eino examples and ADK applications
Include chat, weather, image, travel, streaming ASR and text examples,
shared model initialization, documentation, and existing tests.

Co-authored-by: TRAE CLI <traecli@bytedance.com>
2026-11-19 11:08:03 +08:00

61 lines
2.1 KiB
Go

package config
import "testing"
func TestDefaultsAndInheritance(t *testing.T) {
t.Setenv("AI_KEY", "main-key")
cfg, err := Parse(nil)
if err != nil {
t.Fatal(err)
}
if cfg.Image.Model != "z-image-turbo" || cfg.Image.OutputDir != "./generated" || cfg.MaxToken != 4096 {
t.Fatalf("默认配置 = %+v", cfg)
}
if cfg.Image.BaseURL != cfg.Chat.BaseURL || cfg.Image.APIKey != cfg.Chat.APIKey {
t.Fatal("未指定的连接配置应沿用主助手")
}
}
func TestIndependentConnections(t *testing.T) {
t.Setenv("MAIN_KEY", "main-key")
t.Setenv("IMAGE_KEY", "image-key")
cfg, err := Parse([]string{
"--base-url", "https://main.example/v1/", "--model", "main-model", "--api-key-env", "MAIN_KEY",
"--image-base-url", "https://image.example/v1/", "--image-model", "image-model", "--image-api-key-env", "IMAGE_KEY", "--image-dir", "pictures",
})
if err != nil {
t.Fatal(err)
}
if cfg.Chat != (ModelConfig{BaseURL: "https://main.example/v1", Model: "main-model", APIKey: "main-key"}) {
t.Fatalf("主模型配置 = %+v", cfg.Chat)
}
if cfg.Image.ModelConfig != (ModelConfig{BaseURL: "https://image.example/v1", Model: "image-model", APIKey: "image-key"}) || cfg.Image.OutputDir != "pictures" {
t.Fatalf("图片配置 = %+v", cfg.Image)
}
}
func TestDisableImageAgent(t *testing.T) {
cfg, err := Parse([]string{"--image-model", ""})
if err != nil {
t.Fatal(err)
}
if cfg.Image.Model != "" {
t.Fatal("应允许显式关闭生图工具")
}
}
func TestASRConfig(t *testing.T) {
t.Setenv("VOICE_MAIN_KEY", "shared-key")
cfg, err := Parse([]string{"--api-key-env", "VOICE_MAIN_KEY"})
if err != nil {
t.Fatal(err)
}
if cfg.ASR.BaseURL != "wss://ai.loveuer.com/v1" || cfg.ASR.Model != "local-asr" || cfg.ASR.Device != "0" || cfg.ASR.APIKey != "shared-key" {
t.Fatalf("ASR 默认配置不正确: %+v", cfg.ASR)
}
cfg, err = Parse([]string{"--asr-base-url", "ws://localhost:8000/v1/", "--asr-model", "other", "--asr-device", "2"})
if err != nil || cfg.ASR.BaseURL != "ws://localhost:8000/v1" || cfg.ASR.Model != "other" || cfg.ASR.Device != "2" {
t.Fatalf("ASR 自定义配置不正确,错误 = %v", err)
}
}