package lexicomai import "testing" func TestSetNested(t *testing.T) { m := map[string]any{} setNested(m, "logs.level", "WARN") setNested(m, "device", "cuda:0") setNested(m, "sbs.url", "http://127.0.0.1:6140") if m["device"] != "cuda:0" { t.Errorf("device = %v", m["device"]) } logs, ok := m["logs"].(map[string]any) if !ok || logs["level"] != "WARN" { t.Errorf("logs.level = %#v", m["logs"]) } sbs, ok := m["sbs"].(map[string]any) if !ok || sbs["url"] != "http://127.0.0.1:6140" { t.Errorf("sbs.url = %#v", m["sbs"]) } } func TestConfigMutationGate(t *testing.T) { // read_only=true блокирует мутации независимо от allow_mutate. ro := &Config{ReadOnly: boolPtr(true)} tt := &Target{Alias: "a", AllowMutate: true} if err := (&Manager{}).ensureMutationAllowed(ro, tt); err == nil { t.Error("read_only should block mutations") } // allow_mutate=false блокирует даже при read_only=false. rw := &Config{ReadOnly: boolPtr(false)} if err := (&Manager{}).ensureMutationAllowed(rw, tt); err != nil { t.Errorf("allow_mutate=true should allow: %v", err) } denied := &Target{Alias: "a", AllowMutate: false} if err := (&Manager{}).ensureMutationAllowed(rw, denied); err == nil { t.Error("allow_mutate=false should block") } } func boolPtr(b bool) *bool { return &b } func TestTypedValue(t *testing.T) { cases := []struct { in string want any }{ {"5242880", float64(5242880)}, // число {"true", true}, // булево {"false", false}, {"WARN", "WARN"}, // произвольный текст — строка {"", ""}, // пусто — строка {"\"INFO\"", "INFO"}, } for _, c := range cases { if got := typedValue(c.in); got != c.want { t.Errorf("typedValue(%q) = %#v, want %#v", c.in, got, c.want) } } // не-строка проходит как есть. if got := typedValue(42); got != 42 { t.Errorf("typedValue(non-string) = %#v", got) } } func TestInstallSessionRegistry(t *testing.T) { reg := newInstallSessions() a := reg.add("t", "ups", "release", "7.012", "ups-7.012-release.sh", "/tmp/inst.log") b := reg.add("t", "spr", "release", "", "spr-7.011-release.sh", "/tmp/inst2.log") if a.ID == b.ID { t.Error("session IDs should be unique") } if got, ok := reg.get(a.ID); !ok || got.Product != "ups" { t.Errorf("get(%s) = %+v, ok=%v", a.ID, got, ok) } if _, ok := reg.get("missing"); ok { t.Error("missing session should not exist") } }