docker-archive / go-p9p

A modern, performant 9P library for Go.
Apache License 2.0
206 stars 50 forks source link

Write overflow - test validating truncated writes #31

Closed simonferquel closed 7 years ago

simonferquel commented 7 years ago

This adds a test (that fails on current master), ensuring writes are correctly truncated by the channel, according to msize

simonferquel commented 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.

stevvooe commented 7 years ago

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.

stevvooe commented 7 years ago

@simonferquel I took on this test and few others in #30. Closing.