Add mock for net conn

This commit is contained in:
9seconds
2021-03-09 11:58:06 +03:00
parent 7002e4cd09
commit b5346668f8
3 changed files with 45 additions and 0 deletions
+41
View File
@@ -5,12 +5,53 @@ import (
"net"
"net/http/httptest"
"strings"
"time"
"github.com/mccutchen/go-httpbin/httpbin"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
)
type ConnMock struct {
mock.Mock
}
func (c *ConnMock) Read(b []byte) (int, error) {
args := c.Called(b)
return args.Int(0), args.Error(1)
}
func (c *ConnMock) Write(b []byte) (int, error) {
args := c.Called(b)
return args.Int(0), args.Error(1)
}
func (c *ConnMock) Close() error {
return c.Called().Error(0)
}
func (c *ConnMock) LocalAddr() net.Addr {
return c.Called().Get(0).(net.Addr)
}
func (c *ConnMock) RemoteAddr() net.Addr {
return c.Called().Get(0).(net.Addr)
}
func (c *ConnMock) SetDeadline(t time.Time) error {
return c.Called(t).Error(0)
}
func (c *ConnMock) SetReadDeadline(t time.Time) error {
return c.Called(t).Error(0)
}
func (c *ConnMock) SetWriteDeadline(t time.Time) error {
return c.Called(t).Error(0)
}
type DialerMock struct {
mock.Mock
}