package config import ( "os" "path/filepath" "testing" ) func TestLoadDefaultsWhenNoOverlay(t *testing.T) { dir := t.TempDir() cfg, err := Load(filepath.Join(dir, "missing.yaml")) if err != nil { t.Fatal(err) } if cfg.Version != 1 { t.Errorf("version = %d", cfg.Version) } if len(cfg.ExtraPackages) != 0 { t.Errorf("extra_packages = %v", cfg.ExtraPackages) } } func TestLoadMergesOverlay(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "overlay.yaml") content := []byte(` version: 1 extra_packages: [htop, ncdu] disabled_modules: [renode] theme_overrides: starship: /tmp/mine.toml `) if err := os.WriteFile(path, content, 0o644); err != nil { t.Fatal(err) } cfg, err := Load(path) if err != nil { t.Fatal(err) } if got := cfg.ExtraPackages; len(got) != 2 || got[0] != "htop" || got[1] != "ncdu" { t.Errorf("extra_packages = %v", got) } if len(cfg.DisabledModules) != 1 || cfg.DisabledModules[0] != "renode" { t.Errorf("disabled_modules = %v", cfg.DisabledModules) } if cfg.ThemeOverrides["starship"] != "/tmp/mine.toml" { t.Errorf("theme_overrides = %v", cfg.ThemeOverrides) } } func TestDefaultsCarryModuleInputs(t *testing.T) { cfg, err := Load("/nonexistent/overlay.yaml") if err != nil { t.Fatal(err) } if len(cfg.Packages.Base) == 0 { t.Error("Packages.Base empty") } if len(cfg.Fonts) == 0 { t.Error("Fonts empty") } if cfg.ArduinoCLI.Version == "" { t.Error("ArduinoCLI.Version empty") } if cfg.ArduinoCLI.URL == "" { t.Error("ArduinoCLI.URL empty") } if cfg.Zsh.OhMyZshRepo == "" { t.Error("Zsh.OhMyZshRepo empty") } if len(cfg.ShellConfig.Blocks) == 0 { t.Error("ShellConfig.Blocks empty") } } func TestDefaultsCarryPlan3bInputs(t *testing.T) { cfg, err := Load("/nonexistent/overlay.yaml") if err != nil { t.Fatal(err) } if cfg.Neovim.NvChadStarterRepo == "" { t.Error("Neovim.NvChadStarterRepo empty") } if cfg.Renode.WokwiVersion == "" { t.Error("Renode.WokwiVersion empty") } if cfg.Renode.WokwiURL == "" { t.Error("Renode.WokwiURL empty") } if len(cfg.Renode.Platforms) == 0 { t.Error("Renode.Platforms empty") } want := map[string]string{"stm32f4": "STM32F4_Discovery", "rp2040": "RP2040", "nrf52840": "nRF52840"} for _, p := range cfg.Renode.Platforms { if want[p.Name] != p.Machine { t.Errorf("platform %q: machine=%q want %q", p.Name, p.Machine, want[p.Name]) } } } func TestLoadRejectsUnknownVersion(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "overlay.yaml") if err := os.WriteFile(path, []byte("version: 99\n"), 0o644); err != nil { t.Fatal(err) } if _, err := Load(path); err == nil { t.Fatal("expected version error") } }