From fbb3345518872346a629e7ccbec81f09532765f9 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 23 Jul 2026 13:18:34 +0200 Subject: config: TOML load + seed --- internal/config/config_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 internal/config/config_test.go (limited to 'internal/config/config_test.go') diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..94c33cd --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1,57 @@ +package config + +import ( + "os" + "path/filepath" + "testing" +) + +func TestLoadSeeds(t *testing.T) { + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) + cfg, err := Load() + if err != nil { + t.Fatal(err) + } + if cfg.DefaultVersion != "pl" || cfg.Offline { + t.Errorf("defaults wrong: %+v", cfg) + } + if cfg.Lectionary != "new" { + t.Errorf("lectionary default wrong: %+v", cfg) + } + if _, err := os.Stat(filepath.Join(dir, "lectio", "config.toml")); err != nil { + t.Error("config not seeded") + } +} + +func TestLoadOverride(t *testing.T) { + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) + os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) + os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), + []byte("offline = true\ndefault_version = \"wuj\"\n"), 0o644) + cfg, _ := Load() + if !cfg.Offline || cfg.DefaultVersion != "wuj" { + t.Errorf("override not applied: %+v", cfg) + } +} + +func TestPartShown(t *testing.T) { + var empty Config + if !empty.PartShown("new", "psalm") { + t.Error("nil Parts: psalm should be shown") + } + if !empty.PartShown("new", "ewangelia") { + t.Error("nil Parts: ewangelia should be shown") + } + + hidden := Config{Parts: map[string]map[string]bool{ + "new": {"psalm": false}, + }} + if hidden.PartShown("new", "psalm") { + t.Error("psalm explicitly false should be hidden") + } + if !hidden.PartShown("new", "ewangelia") { + t.Error("ewangelia not mentioned should still be shown") + } +} -- cgit v1.3