aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config_test.go
blob: 94c33cde145971066637ae255039dbe0f7f94c7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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")
	}
}