-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
61 lines (55 loc) · 1.09 KB
/
config_test.go
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
58
59
60
61
package godm
import (
"os"
"path/filepath"
"reflect"
"testing"
)
func TestLoadConfig(t *testing.T) {
pwd, _ := os.Getwd()
reset := setTestEnv("HOME", pwd)
defer reset()
pattern := map[string]struct {
confdir string
want *config
isErr bool
}{
"xdg_ok": {
confdir: filepath.Join(pwd, "testdata"),
want: &config{
Installpath: "$HOME/.dotfiles",
Dirs: []string{"path/to/test", "path/to/test1"},
Tools: [][]string{
{"go", "install", "github.com/halkn/godm/cmd/godm@latest"},
{"npm", "install", "-g", "npm"},
},
},
isErr: false,
},
"xdg_ng": {
confdir: filepath.Join(pwd, "testdataF"),
want: nil,
isErr: true,
},
"home": {
confdir: "",
want: nil,
isErr: true,
},
}
for k, tt := range pattern {
t.Run(k, func(t *testing.T) {
reset := setTestEnv("XDG_CONFIG_HOME", tt.confdir)
defer reset()
got, err := loadConfig()
if tt.isErr {
if err == nil {
t.Fatal("expected error")
}
}
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("got: %v, want: %v", got, tt.want)
}
})
}
}