-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsockets_list_test.go
54 lines (42 loc) · 1.05 KB
/
sockets_list_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
package tinytcp
import (
"github.com/stretchr/testify/assert"
"net"
"testing"
)
func TestSocketsListSimple(t *testing.T) {
// given
list := newSocketsList(-1)
connections := []net.Conn{&ConnMock{}, &ConnMock{}, &ConnMock{}}
sockets := make([]*Socket, len(connections))
// when
for i, conn := range connections {
sockets[i] = list.New(conn)
}
list.Cleanup()
// then
assert.Equal(t, len(sockets), list.Len(), "sockets count should match")
}
func TestSocketsListCleanup(t *testing.T) {
// given
list := newSocketsList(-1)
connections := []net.Conn{&ConnMock{}, &ConnMock{}, &ConnMock{}}
sockets := make([]*Socket, len(connections))
// when
for i, conn := range connections {
sockets[i] = list.New(conn)
}
_ = sockets[0].Recycle()
list.Cleanup()
// then
assert.Equal(t, len(sockets)-1, list.Len(), "sockets count should match")
}
func TestSocketsListLimit(t *testing.T) {
// given
list := newSocketsList(0)
connection := &ConnMock{}
// when
socket := list.New(connection)
// then
assert.Nil(t, socket, "socket should not be returned")
}