first commit
This commit is contained in:
commit
3553790475
27 files changed
+3839
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDefaultIsUsable(t *testing.T) {
|
||||
cfg := Default()
|
||||
cfg.Normalize()
|
||||
|
||||
if len(cfg.Profiles) == 0 {
|
||||
t.Fatal("默认配置应包含接入点")
|
||||
}
|
||||
if cfg.Active().Name != "qwen" {
|
||||
t.Fatalf("默认接入点应为 qwen,实际 %s", cfg.Active().Name)
|
||||
}
|
||||
if cfg.Capture.FPS <= 0 || cfg.Capture.MaxEdge <= 0 || cfg.Capture.CooldownMs <= 0 {
|
||||
t.Fatalf("抓屏参数不应为零值: %+v", cfg.Capture)
|
||||
}
|
||||
if tmpl := cfg.Template("exercise"); tmpl.Key != "exercise" {
|
||||
t.Fatalf("应能取到习题模板,实际 %s", tmpl.Key)
|
||||
}
|
||||
if tmpl := cfg.Template("not-exist"); tmpl.Key == "" {
|
||||
t.Fatal("未知模板应回退到第一个模板")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeFillsZeroValues(t *testing.T) {
|
||||
cfg := &Config{}
|
||||
cfg.Normalize()
|
||||
|
||||
if cfg.ActiveProfile == "" {
|
||||
t.Fatal("Normalize 应补全 ActiveProfile")
|
||||
}
|
||||
if len(cfg.Templates) == 0 {
|
||||
t.Fatal("Normalize 应补全模板")
|
||||
}
|
||||
if cfg.Capture.JPEGQuality == 0 || cfg.Capture.StableFrames == 0 || cfg.Capture.HistoryTurns == 0 {
|
||||
t.Fatalf("Normalize 应补全抓屏参数: %+v", cfg.Capture)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneIsIndependent(t *testing.T) {
|
||||
cfg := Default()
|
||||
cfg.Normalize()
|
||||
|
||||
cp := cfg.Clone()
|
||||
cp.Profiles[0].Model = "changed"
|
||||
cp.Templates[0].System = "changed"
|
||||
cp.Capture.FPS = 9
|
||||
|
||||
if cfg.Profiles[0].Model == "changed" {
|
||||
t.Fatal("Clone 后修改接入点不应影响原配置")
|
||||
}
|
||||
if cfg.Templates[0].System == "changed" {
|
||||
t.Fatal("Clone 后修改模板不应影响原配置")
|
||||
}
|
||||
if cfg.Capture.FPS == 9 {
|
||||
t.Fatal("Clone 后修改抓屏参数不应影响原配置")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfileLookup(t *testing.T) {
|
||||
cfg := Default()
|
||||
cfg.Normalize()
|
||||
|
||||
if _, ok := cfg.Profile("qwen"); !ok {
|
||||
t.Fatal("应能找到 qwen 接入点")
|
||||
}
|
||||
if _, ok := cfg.Profile("不存在"); ok {
|
||||
t.Fatal("不应找到不存在的接入点")
|
||||
}
|
||||
cfg.ActiveProfile = "不存在"
|
||||
if cfg.Active().Name != cfg.Profiles[0].Name {
|
||||
t.Fatal("接入点丢失时应回退到第一个")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user