forked from taliesinb/go-imap
-
Notifications
You must be signed in to change notification settings - Fork 3
/
protocol_test.go
67 lines (61 loc) · 1.29 KB
/
protocol_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
package imap
import (
"bytes"
"testing"
"reflect"
)
type readerTest struct {
input string
expectedTag tag
expectedResponse interface{}
}
func (rt readerTest) Run(t *testing.T) {
r := &reader{newParser(bytes.NewBufferString(rt.input))}
tag, resp, err := r.readResponse()
check(err)
if tag != rt.expectedTag {
t.Fatalf("expected %v, got %v", rt.expectedTag, tag)
}
if !reflect.DeepEqual(resp, rt.expectedResponse) {
t.Fatalf("DeepEqual(%#v, %#v)", resp, rt.expectedResponse)
}
}
func TestProtocol(t *testing.T) {
tests := []readerTest{
readerTest{
"* OK Gimap ready for requests from 12.34 u6if.369\r\n",
untagged,
&ResponseStatus{
status: OK,
text: "Gimap ready for requests from 12.34 u6if.369",
},
},
readerTest{
"* OK [PERMANENTFLAGS ()] Flags permitted.\r\n",
untagged,
&ResponsePermanentFlags{[]string{}},
},
readerTest{
"* OK [UIDVALIDITY 2] UIDs valid.\r\n",
untagged,
&ResponseUIDValidity{2},
},
readerTest{
"* OK [UIDNEXT 31677] Predicted next UID.\r\n",
untagged,
&ResponseUIDNext{31677},
},
readerTest{
"a2 OK [READ-ONLY] INBOX selected. (Success)\r\n",
tag(2),
&ResponseStatus{
status: OK,
code:"READ-ONLY",
text:"INBOX selected. (Success)",
},
},
}
for _, test := range tests {
test.Run(t)
}
}