aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 12:53:34 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 12:53:34 +0200
commit809a47a227540ad8b8b2ac28a1bbbc2f115b7406 (patch)
tree03e609b85ebef46867166469b79a1c01b6c93f7d /internal/config/config_test.go
parent06e32c85a5b8b0aaf5539a989347fbe68e27b95e (diff)
downloadlectio-809a47a227540ad8b8b2ac28a1bbbc2f115b7406.tar.gz
lectio-809a47a227540ad8b8b2ac28a1bbbc2f115b7406.zip
feat(config): migrate to INI + one-shot TOML conversion + calendar Selection
config.Load/Save now read/write config.ini; a pre-existing config.toml is converted once (old file kept, reversible). New [calendar] section (epiphany/ascension/corpus_christi) + Config.Selection() feeding the engine. Config struct API unchanged, so daily-readings and web /settings keep working.
Diffstat (limited to 'internal/config/config_test.go')
-rw-r--r--internal/config/config_test.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 53a3980..38c7604 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -19,7 +19,7 @@ func TestLoadSeeds(t *testing.T) {
if cfg.Lectionary != "new" {
t.Errorf("lectionary default wrong: %+v", cfg)
}
- if _, err := os.Stat(filepath.Join(dir, "lectio", "config.toml")); err != nil {
+ if _, err := os.Stat(filepath.Join(dir, "lectio", "config.ini")); err != nil {
t.Error("config not seeded")
}
}
@@ -201,7 +201,7 @@ func TestSiglaStyleDefaultsAndDialect(t *testing.T) {
func TestSaveRoundTrip(t *testing.T) {
dir := t.TempDir()
- path := filepath.Join(dir, "config.toml")
+ path := filepath.Join(dir, "config.ini")
t.Setenv("LECTIO_CONFIG", path)
cfg := Default()
@@ -224,6 +224,43 @@ func TestSaveRoundTrip(t *testing.T) {
}
}
+func TestSelectionFromINI(t *testing.T) {
+ dir := t.TempDir()
+ t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
+ os.WriteFile(filepath.Join(dir, "config.ini"),
+ []byte("lectionary = new\n[calendar]\nepiphany = sunday\nascension = sunday\n"), 0o644)
+ cfg, err := Load()
+ if err != nil {
+ t.Fatal(err)
+ }
+ sel := cfg.Selection()
+ if sel.Form != "new" || sel.Epiphany != "sunday" || sel.Ascension != "sunday" || sel.CorpusChristi != "thursday" {
+ t.Fatalf("selection = %+v", sel)
+ }
+}
+
+func TestMigrateTOMLToINI(t *testing.T) {
+ dir := t.TempDir()
+ t.Setenv("XDG_CONFIG_HOME", dir)
+ os.MkdirAll(filepath.Join(dir, "lectio"), 0o755)
+ // only the old TOML exists -> Load converts once and writes config.ini.
+ os.WriteFile(filepath.Join(dir, "lectio", "config.toml"),
+ []byte("ui_language = \"pl\"\ndefault_version = \"wuj\"\n"), 0o644)
+ cfg, err := Load()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if cfg.UILanguage != "pl" || cfg.DefaultVersion != "wuj" {
+ t.Errorf("migrated values wrong: %+v", cfg)
+ }
+ if _, err := os.Stat(filepath.Join(dir, "lectio", "config.ini")); err != nil {
+ t.Error("config.ini not written on migration")
+ }
+ if _, err := os.Stat(filepath.Join(dir, "lectio", "config.toml")); err != nil {
+ t.Error("old config.toml should be kept (reversible)")
+ }
+}
+
func TestPartShown(t *testing.T) {
var empty Config
if !empty.PartShown("new", "psalm") {