Closed simonferquel closed 7 years ago
@stevvooe this test should make it easier to validate #30. I am not completely happy with the fake net.Addr / net.Conn implementation (it is quite verbose), but it correctly exhibits the problem.
I'll do a second PR to test for read overflows.
I am not completely happy with the fake net.Addr / net.Conn implementation (it is quite verbose), but it correctly exhibits the problem.
When mocking an interface, it is easiest to start with a stub, embedded implementation and then implement the calls required for the tests:
type mockConn struct {
net.Conn
}
The above implements net.Conn
with a nil receiver. Any calls to unimplemented methods will panic. When you want behavior, simply override the target method:
func (c *mockConn) Write(b []byte) (n int, err error) {
c.data = append(c.data, b...)
n = len(b)
return n, nil
}
This looks okay. I can make some adjustments in #30 after a few fixes.
@simonferquel I took on this test and few others in #30. Closing.
This adds a test (that fails on current master), ensuring writes are correctly truncated by the channel, according to msize