-
Notifications
You must be signed in to change notification settings - Fork 27
/
cmd_categories_test.go
71 lines (62 loc) · 1.13 KB
/
cmd_categories_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
package notes
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestCategoriesCmd(t *testing.T) {
cwd, err := os.Getwd()
panicIfErr(err)
for _, tc := range []struct {
what string
subdir string
want string
}{
{
what: "flat",
subdir: "normal",
want: "a\nb\nc\n",
},
{
what: "nested",
subdir: "nested",
want: "a\na/d\na/d/e\nb\nb/f\nc\n",
},
} {
t.Run(tc.what, func(t *testing.T) {
cfg := &Config{
HomePath: filepath.Join(cwd, "testdata", "list", tc.subdir),
}
var buf bytes.Buffer
cmd := CategoriesCmd{
Config: cfg,
Out: &buf,
}
if err := cmd.Do(); err != nil {
t.Fatal(err)
}
have := buf.String()
want := tc.want
if have != want {
t.Fatal("wanted:", want, "but have", have)
}
})
}
}
func TestCategoriesCmdError(t *testing.T) {
cfg := &Config{
HomePath: filepath.FromSlash("/path/to/somewhere/unknown/home"),
}
cmd := CategoriesCmd{
Config: cfg,
}
err := cmd.Do()
if err == nil {
t.Fatal("Error did not occur")
}
if !strings.Contains(err.Error(), "Cannot read home") {
t.Fatal("Unexpected error:", err)
}
}