-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_command_test.go
70 lines (59 loc) · 1.78 KB
/
server_command_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
// Copyright 2014 The imapsrv Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the imapsrv.LICENSE file.
package imap
import "testing"
import "fmt"
func setupTest() (*Server, *session) {
m := &TestMailstore{}
s := NewServer(
Store(m),
)
//s.Start()
sess := createSession(1, s.config)
return s, sess
}
// A test mailstore used for unit testing
type TestMailstore struct {
}
// Get mailbox information
func (m *TestMailstore) GetMailbox(name string) (*Mailbox, error) {
return &Mailbox{
Name: "inbox",
Id: 1,
}, nil
}
// Get the sequence number of the first unseen message
func (m *TestMailstore) FirstUnseen(mbox int64) (int64, error) {
return 4, nil
}
// Get the total number of messages in an IMAP mailbox
func (m *TestMailstore) TotalMessages(mbox int64) (int64, error) {
return 8, nil
}
// Get the total number of unread messages in an IMAP mailbox
func (m *TestMailstore) RecentMessages(mbox int64) (int64, error) {
return 4, nil
}
// Get the next available uid in an IMAP mailbox
func (m *TestMailstore) NextUid(mbox int64) (int64, error) {
return 9, nil
}
func TestCapabilityCommand(t *testing.T) {
_, session := setupTest()
cap := &capability{tag: "A00001"}
resp := cap.execute(session)
if (resp.tag != "A00001") || (resp.message != "CAPABILITY completed") || (resp.untagged[0] != "CAPABILITY IMAP4rev1") {
t.Error("Capability Failed - unexpected response.")
fmt.Println(resp)
}
}
func TestLogoutCommand(t *testing.T) {
_, session := setupTest()
log := &logout{tag: "A00004"}
resp := log.execute(session)
if (resp.tag != "A00004") || (resp.message != "LOGOUT completed") || (resp.untagged[0] != "BYE IMAP4rev1 Server logging out") {
t.Error("Logout Failed - unexpected response.")
fmt.Println(resp)
}
}