BlueGit

timfa bluegit

Files

bluegit / internal / apppaths / apppaths_test.go

apppaths_test.go

apppaths_test.go 1.7 KiB Download Raw
1package apppaths
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestDataDirLinuxKeepsVarLib(t *testing.T) {
10 got := dataDir("linux", `C:\Users\tim\AppData\Local`, "/var/lib/bluegit", "BlueGit")
11 if got != "/var/lib/bluegit" {
12 t.Fatalf("linux: %s", got)
13 }
14}
15
16func TestDataDirWindowsUsesLocalAppData(t *testing.T) {
17 got := dataDir("windows", `C:\Users\tim\AppData\Local`, "/var/lib/bluegit", "BlueGit")
18 want := filepath.Join(`C:\Users\tim\AppData\Local`, "BlueGit")
19 if got != want {
20 t.Fatalf("windows: %s, wil %s", got, want)
21 }
22}
23
24func TestConfigFileOrder(t *testing.T) {
25 dir := t.TempDir()
26 cwd := filepath.Join(dir, "bluegit.yml")
27 if err := os.WriteFile(cwd, []byte("x\n"), 0o644); err != nil {
28 t.Fatal(err)
29 }
30 // Een gezet pad wint van alles, ook van een bestaande cwd-file.
31 if got := configFile("linux", "", "/env.yml", "/explicit.yml", cwd, "/etc/bluegit/config.yml", "BlueGit"); got != "/explicit.yml" {
32 t.Fatalf("explicit: %s", got)
33 }
34 if got := configFile("linux", "", "/env.yml", "", cwd, "/etc/bluegit/config.yml", "BlueGit"); got != "/env.yml" {
35 t.Fatalf("env: %s", got)
36 }
37 if got := configFile("linux", "", "", "", cwd, "/etc/bluegit/config.yml", "BlueGit"); got != cwd {
38 t.Fatalf("cwd: %s", got)
39 }
40 if got := configFile("linux", "", "", "", filepath.Join(dir, "ontbreekt.yml"), "/etc/bluegit/config.yml", "BlueGit"); got != "/etc/bluegit/config.yml" {
41 t.Fatalf("linux default: %s", got)
42 }
43 got := configFile("windows", `C:\Users\tim\AppData\Local`, "", "", filepath.Join(dir, "ontbreekt.yml"), "/etc/bluegit/config.yml", "BlueGit")
44 want := filepath.Join(`C:\Users\tim\AppData\Local`, "BlueGit", "config.yml")
45 if got != want {
46 t.Fatalf("windows default: %s, wil %s", got, want)
47 }
48}