-
Notifications
You must be signed in to change notification settings - Fork 1
/
proto_test.go
81 lines (79 loc) · 1.62 KB
/
proto_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
package main
import (
"bufio"
"errors"
"io/ioutil"
"log"
"reflect"
"strings"
"testing"
)
func TestReadInodes(t *testing.T) {
log.SetOutput(ioutil.Discard)
type cas struct {
payload string
want []Inode
err error
}
for n, c := range []cas{
{
payload: `file: 2.Foreword_2_Amanda_Palmer.flac
Last-Modified: 2018-01-10T12:39:15Z
Time: 798
duration: 797.794
Title: Foreword 2 Amanda Palmer
Artist: Amanda Palmer
AlbumArtist: Cory Doctorow
Album: Information Doesn't Want To Be Free
Genre: Audiobook
Composer: Cory Doctorow
Performer: Cory Doctorow
directory: Elliott Smith - Either-Or
Last-Modified: 2015-03-01T13:51:33Z
directory: Elliott Smith - Elliott Smith
Last-Modified: 2015-03-01T13:51:46Z
OK
`,
want: []Inode{
{
File: &IEntry{
ID: "2.Foreword_2_Amanda_Palmer.flac",
Title: "2.Foreword_2_Amanda_Palmer.flac",
},
},
{
Dir: &IEntry{
ID: "Elliott Smith - Either-Or",
Title: "Elliott Smith - Either-Or",
},
},
{
Dir: &IEntry{
ID: "Elliott Smith - Elliott Smith",
Title: "Elliott Smith - Elliott Smith",
},
},
},
},
{
payload: "OK\n",
want: []Inode{},
},
{
payload: "foo\n",
err: errors.New("unexpected line"),
},
} {
kv, err := readKV(bufio.NewReader(strings.NewReader(c.payload)))
if have, want := err, c.err; !reflect.DeepEqual(have, want) {
t.Errorf("case %d: have %q, want %q", n, have, want)
continue
}
if c.err != nil {
continue
}
if have, want := readInodes(kv), c.want; !reflect.DeepEqual(have, want) {
t.Errorf("case %d: have %#v, want %#v", n, have, want)
}
}
}