-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
85 lines (71 loc) · 1.71 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gito
import (
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
type mockConfigFile struct {
io.Reader
}
func newMockConfigFile(s string) File {
return &mockConfigFile{
Reader: strings.NewReader(s),
}
}
func (f *mockConfigFile) Write(p []byte) (n int, err error) {
return 0, nil
}
func (f *mockConfigFile) Sync() error {
return nil
}
func (f *mockConfigFile) Truncate(int64) error {
return nil
}
func (f *mockConfigFile) Seek(offset int64, whence int) (int64, error) {
return 0, nil
}
func (f *mockConfigFile) Close() error {
return nil
}
func TestLoad(t *testing.T) {
r := `workspaces:
- name: personal
path: "/Users/ricky"
aliases:
g: gito
d: dotfiles
custom:
dotfiles: "/Users/ricky/.dotfiles"
- name: work
path: "/Users/ricky/gh"
aliases:
ghe: super-secret
custom:
super-secret: "somewhereElse/theMoneyMaker"`
f := newMockConfigFile(r)
config := &Config{f: f}
err := loadConfig(f, config, false, "")
if err != nil {
t.Fatalf("unexpected error loading config: %v", err)
}
got := config.Workspaces[0]
want := &Workspace{
Name: "personal",
Path: "/Users/ricky",
path: []string{"/Users/ricky/src"},
Aliases: map[string]string{"g": "gito", "d": "dotfiles"},
Custom: map[string]string{"dotfiles": "/Users/ricky/.dotfiles"},
}
assert := assert.New(t)
assert.Equal(want, got)
got = config.Workspaces[1]
want = &Workspace{
Name: "work",
Path: "/Users/ricky/gh",
path: []string{"/Users/ricky/gh/src"},
Aliases: map[string]string{"ghe": "super-secret"},
Custom: map[string]string{"super-secret": "somewhereElse/theMoneyMaker"},
}
assert.Equal(want, got)
}