forked from emersion/go-imap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_test.go
94 lines (85 loc) · 2.11 KB
/
status_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
82
83
84
85
86
87
88
89
90
91
92
93
94
package imap_test
import (
"bytes"
"testing"
"github.com/emersion/go-imap"
)
func TestStatusResp_WriteTo(t *testing.T) {
tests := []struct {
input *imap.StatusResp
expected string
}{
{
input: &imap.StatusResp{
Tag: "*",
Type: imap.StatusRespOk,
},
expected: "* OK \r\n",
},
{
input: &imap.StatusResp{
Tag: "*",
Type: imap.StatusRespOk,
Info: "LOGIN completed",
},
expected: "* OK LOGIN completed\r\n",
},
{
input: &imap.StatusResp{
Tag: "42",
Type: imap.StatusRespBad,
Info: "Invalid arguments",
},
expected: "42 BAD Invalid arguments\r\n",
},
{
input: &imap.StatusResp{
Tag: "a001",
Type: imap.StatusRespOk,
Code: "READ-ONLY",
Info: "EXAMINE completed",
},
expected: "a001 OK [READ-ONLY] EXAMINE completed\r\n",
},
{
input: &imap.StatusResp{
Tag: "*",
Type: imap.StatusRespOk,
Code: "CAPABILITY",
Arguments: []interface{}{imap.RawString("IMAP4rev1")},
Info: "IMAP4rev1 service ready",
},
expected: "* OK [CAPABILITY IMAP4rev1] IMAP4rev1 service ready\r\n",
},
}
for i, test := range tests {
b := &bytes.Buffer{}
w := imap.NewWriter(b)
if err := test.input.WriteTo(w); err != nil {
t.Errorf("Cannot write status #%v, got error: %v", i, err)
continue
}
o := b.String()
if o != test.expected {
t.Errorf("Invalid output for status #%v: %v", i, o)
}
}
}
func TestStatus_Err(t *testing.T) {
status := &imap.StatusResp{Type: imap.StatusRespOk, Info: "All green"}
if err := status.Err(); err != nil {
t.Error("OK status returned error:", err)
}
status = &imap.StatusResp{Type: imap.StatusRespBad, Info: "BAD!"}
if err := status.Err(); err == nil {
t.Error("BAD status didn't returned error:", err)
} else if err.Error() != "BAD!" {
t.Error("BAD status returned incorrect error message:", err)
}
status = &imap.StatusResp{Type: imap.StatusRespNo, Info: "NO!"}
if err := status.Err(); err == nil {
t.Error("NO status didn't returned error:", err)
} else if err.Error() != "NO!" {
t.Error("NO status returned incorrect error message:", err)
}
}