forked from genert/pop3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_test.go
59 lines (47 loc) · 1.06 KB
/
connection_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
package pop3_test
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/genert/pop3"
)
func TestConnection_Cmd(t *testing.T) {
testCases := []struct {
response string
command string
}{
{
"+OK 13 messages:\r\n",
"STAT",
},
{
"+OK\r\n",
"LIST 1",
},
}
for _, tt := range testCases {
var tt = tt
var buffer []byte
buffer = make([]byte, 0)
var fake readWriteFaker
fake.Reader = strings.NewReader(tt.response)
fake.Writer = &fakeWriter{buffer: &buffer}
fake.Closer = &fakeCloser{}
connection := pop3.NewConnection(fake)
response, err := connection.Cmd(tt.command)
assert.Nil(t, err)
assert.NotEmpty(t, t, response)
assert.Equal(t, fmt.Sprintf("%s\r\n", tt.command), string(buffer))
}
}
func TestConnection_Close(t *testing.T) {
var buffer []byte
buffer = make([]byte, 0)
var fake readWriteFaker
fake.Reader = strings.NewReader("+OK\r\n")
fake.Writer = &fakeWriter{buffer: &buffer}
fake.Closer = &fakeCloser{}
connection := pop3.NewConnection(fake)
assert.Nil(t, connection.Close())
}