-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.go
69 lines (58 loc) · 1.54 KB
/
list_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
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"path/filepath"
"strings"
"testing"
)
func TestListCommand(t *testing.T) {
out := new(bytes.Buffer)
dummyUI := &baseUI{
writer: out,
errWriter: new(bytes.Buffer),
reader: new(bytes.Buffer),
}
cmd := &ListCommand{
ui: dummyUI,
}
t.Run("display nothing when number of bookmarks is 0", func(t *testing.T) {
_, cleanup := setupForCommandTest(t)
defer cleanup()
code := cmd.Run(nil)
if code != 0 {
t.Fatalf("expected normal status code, but got abnormal code: %d", code)
}
if out.Len() != 0 {
t.Errorf("expected empty string, but got not empty string: %s", out.String())
}
})
t.Run("display bookmarks which is stored in the DB", func(t *testing.T) {
_, cleanup := setupForCommandTest(t)
defer cleanup()
// setup: load testdata
b, err := ioutil.ReadFile(filepath.Join("testdata", "list.json"))
if err != nil {
t.Fatalf("failed to open testdata: %s", err)
}
var db DB
if err := json.Unmarshal(b, &db); err != nil {
t.Fatalf("failed to unmarshal testdata: %s", err)
}
repo = &Repository{
Bookmark: newJSONBookmarkRepository(&db),
}
// do
code := cmd.Run(nil)
if code != 0 {
t.Fatalf("expected normal status code, but got abnormal code: %d", code)
}
if !strings.Contains(out.String(), "google") {
t.Errorf("expected output contains '%s', but missing", "google")
}
if !strings.Contains(out.String(), "https://google.com") {
t.Errorf("expected output contains '%s', but missing", "https://google.com")
}
})
}