diff options
Diffstat (limited to 'internal/config/config_test.go')
| -rw-r--r-- | internal/config/config_test.go | 41 |
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") { |
