Refactor config pkg

This commit is contained in:
dwrz
2026-09-25 18:26:54 +00:00
parent 7ac72cef6a
commit bcf13888fb
2 changed files with 137 additions and 70 deletions
+41 -31
View File
@@ -62,16 +62,10 @@ func TestLoad(t *testing.T) {
cfg.Address, ":9090",
)
}
if cfg.ShutdownTimeout != "60s" {
if cfg.ShutdownTimeout != 60*time.Second {
t.Errorf(
"ShutdownTimeout = %q, want %q",
cfg.ShutdownTimeout, "60s",
)
}
if cfg.GetShutdownTimeout() != 60*time.Second {
t.Errorf(
"GetShutdownTimeout() = %v, want 60s",
cfg.GetShutdownTimeout(),
"ShutdownTimeout = %v, want %v",
cfg.ShutdownTimeout, 60*time.Second,
)
}
},
@@ -104,16 +98,10 @@ tts:
cfg.Address, ":8080",
)
}
if cfg.ShutdownTimeout != "30s" {
if cfg.ShutdownTimeout != 30*time.Second {
t.Errorf(
"ShutdownTimeout = %q, want %q",
cfg.ShutdownTimeout, "30s",
)
}
if cfg.GetShutdownTimeout() != 30*time.Second {
t.Errorf(
"GetShutdownTimeout() = %v, want 30s",
cfg.GetShutdownTimeout(),
"ShutdownTimeout = %v, want %v",
cfg.ShutdownTimeout, 30*time.Second,
)
}
},
@@ -419,6 +407,32 @@ tools:
- name: ""
description: missing name
command: echo
`,
shouldErr: true,
},
{
name: "invalid tool timeout",
config: `
default_model:
provider: testprovider
model: test-model
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
tts:
url: http://localhost:8880
voice: af_heart
tools:
- name: echo
description: echoes input
command: echo
timeout: "-1s"
`,
shouldErr: true,
},
@@ -464,10 +478,10 @@ func TestApplyDefaults(t *testing.T) {
if cfg.Address != ":8080" {
t.Errorf("Address = %q, want %q", cfg.Address, ":8080")
}
if cfg.ShutdownTimeout != "30s" {
if cfg.ShutdownTimeout != 30*time.Second {
t.Errorf(
"ShutdownTimeout = %q, want %q",
cfg.ShutdownTimeout, "30s",
"ShutdownTimeout = %v, want %v",
cfg.ShutdownTimeout, 30*time.Second,
)
}
}
@@ -475,17 +489,17 @@ func TestApplyDefaults(t *testing.T) {
func TestApplyDefaults_NoOverwrite(t *testing.T) {
cfg := &Config{
Address: ":9999",
ShutdownTimeout: "120s",
ShutdownTimeout: 120 * time.Second,
}
cfg.ApplyDefaults()
if cfg.Address != ":9999" {
t.Errorf("Address = %q, want %q", cfg.Address, ":9999")
}
if cfg.ShutdownTimeout != "120s" {
if cfg.ShutdownTimeout != 120*time.Second {
t.Errorf(
"ShutdownTimeout = %q, want %q",
cfg.ShutdownTimeout, "120s",
"ShutdownTimeout = %v, want %v",
cfg.ShutdownTimeout, 120*time.Second,
)
}
}
@@ -540,12 +554,8 @@ jobs:
if j.Schedule != "0 9 * * *" {
t.Errorf("Schedule = %q, want %q", j.Schedule, "0 9 * * *")
}
timeout, err := time.ParseDuration(j.Timeout)
if err != nil {
t.Fatalf("ParseDuration(%q) error = %v", j.Timeout, err)
}
if timeout.Minutes() != 10 {
t.Errorf("Timeout = %v, want 10m", timeout)
if j.Timeout != 10*time.Minute {
t.Errorf("Timeout = %v, want 10m", j.Timeout)
}
if j.MaxIterations != 20 {
t.Errorf("MaxIterations = %d, want 20", j.MaxIterations)