-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcmd_config_test.go
75 lines (72 loc) · 1.21 KB
/
cmd_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
package notes
import (
"bytes"
"strings"
"testing"
)
func TestConfigCmd(t *testing.T) {
cfg := &Config{
HomePath: "/path/to/home",
GitPath: "/path/to/git",
EditorCmd: "vim",
}
for _, tc := range []struct {
name string
want string
}{
{
name: "",
want: "HOME=/path/to/home\nGIT=/path/to/git\nEDITOR=vim\n",
},
{
name: "home",
want: "/path/to/home\n",
},
{
name: "git",
want: "/path/to/git\n",
},
{
name: "editor",
want: "vim\n",
},
{
name: "HOME",
want: "/path/to/home\n",
},
} {
t.Run(tc.name, func(t *testing.T) {
var buf bytes.Buffer
c := ConfigCmd{
Config: cfg,
Name: tc.name,
Out: &buf,
}
if err := c.Do(); err != nil {
t.Fatal(err)
}
have := buf.String()
if have != tc.want {
t.Fatalf("want '%#v' but have '%#v'", tc.want, have)
}
})
}
}
func TestConfigCmdError(t *testing.T) {
cfg := &Config{
HomePath: "/path/to/home",
GitPath: "/path/to/git",
EditorCmd: "vim",
}
c := ConfigCmd{
Config: cfg,
Name: "unknown name",
}
err := c.Do()
if err == nil {
t.Fatal("Error did not occur")
}
if !strings.Contains(err.Error(), "Unknown config name") {
t.Fatal("Unexpected error:", err)
}
}