-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
38 lines (35 loc) · 893 Bytes
/
server_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
package gnet
import (
"errors"
"github.com/NotFound1911/gnet/mocks"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"net"
"testing"
)
// $GOPATH/bin/mockgen -destination=mocks/net_conn.gen.go -package=mocks net Conn
func TestHandleConn(t *testing.T) {
testCases := []struct {
name string
mock func(controller *gomock.Controller) net.Conn
wantErr error
}{
{
name: "read error",
mock: func(controller *gomock.Controller) net.Conn {
conn := mocks.NewMockConn(controller)
conn.EXPECT().Read(gomock.Any()).Return(0, errors.New("read error"))
return conn
},
wantErr: errors.New("read error"),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()
err := handleConn(tc.mock(controller))
assert.Equal(t, tc.wantErr, err)
})
}
}