aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:18:34 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:18:34 +0200
commitfbb3345518872346a629e7ccbec81f09532765f9 (patch)
tree0f07371550d3dc1885d92d99c8aa847223b875ae /internal/config/config_test.go
parent8a401a84af52c94f991c74443b7f4397e30cad4a (diff)
downloadlectio-fbb3345518872346a629e7ccbec81f09532765f9.tar.gz
lectio-fbb3345518872346a629e7ccbec81f09532765f9.zip
config: TOML load + seed
Diffstat (limited to 'internal/config/config_test.go')
-rw-r--r--internal/config/config_test.go57
1 files changed, 57 insertions, 0 deletions
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")
+ }
+}