Explorar el Código

Add mock for net conn

tags/v2.0.0-rc1
9seconds hace 5 años
padre
commit
b5346668f8
Se han modificado 3 ficheros con 45 adiciones y 0 borrados
  1. 1
    0
      go.mod
  2. 3
    0
      go.sum
  3. 41
    0
      mtglib/network/init_test.go

+ 1
- 0
go.mod Ver fichero

@@ -8,6 +8,7 @@ require (
8 8
 	github.com/libp2p/go-reuseport v0.0.2
9 9
 	github.com/mccutchen/go-httpbin v1.1.1
10 10
 	github.com/pelletier/go-toml v1.8.1
11
+	github.com/stretchr/objx v0.3.0 // indirect
11 12
 	github.com/stretchr/testify v1.7.0
12 13
 	golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
13 14
 )

+ 3
- 0
go.sum Ver fichero

@@ -16,6 +16,9 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
16 16
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
17 17
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18 18
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19
+github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
20
+github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
21
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
19 22
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
20 23
 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
21 24
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

+ 41
- 0
mtglib/network/init_test.go Ver fichero

@@ -5,12 +5,53 @@ import (
5 5
 	"net"
6 6
 	"net/http/httptest"
7 7
 	"strings"
8
+	"time"
8 9
 
9 10
 	"github.com/mccutchen/go-httpbin/httpbin"
10 11
 	"github.com/stretchr/testify/mock"
11 12
 	"github.com/stretchr/testify/suite"
12 13
 )
13 14
 
15
+type ConnMock struct {
16
+	mock.Mock
17
+}
18
+
19
+func (c *ConnMock) Read(b []byte) (int, error) {
20
+	args := c.Called(b)
21
+
22
+	return args.Int(0), args.Error(1)
23
+}
24
+
25
+func (c *ConnMock) Write(b []byte) (int, error) {
26
+	args := c.Called(b)
27
+
28
+	return args.Int(0), args.Error(1)
29
+}
30
+
31
+func (c *ConnMock) Close() error {
32
+	return c.Called().Error(0)
33
+}
34
+
35
+func (c *ConnMock) LocalAddr() net.Addr {
36
+	return c.Called().Get(0).(net.Addr)
37
+}
38
+
39
+func (c *ConnMock) RemoteAddr() net.Addr {
40
+	return c.Called().Get(0).(net.Addr)
41
+}
42
+
43
+func (c *ConnMock) SetDeadline(t time.Time) error {
44
+	return c.Called(t).Error(0)
45
+}
46
+
47
+func (c *ConnMock) SetReadDeadline(t time.Time) error {
48
+	return c.Called(t).Error(0)
49
+}
50
+
51
+func (c *ConnMock) SetWriteDeadline(t time.Time) error {
52
+	return c.Called(t).Error(0)
53
+}
54
+
14 55
 type DialerMock struct {
15 56
 	mock.Mock
16 57
 }

Loading…
Cancelar
Guardar