diff options
author | Tamir Duberstein <tamird@google.com> | 2021-01-15 15:47:13 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-15 15:49:15 -0800 |
commit | 12d9790833cc2f6a9b197066a5ecbeb434f74164 (patch) | |
tree | e9eec8e4c755c33c5a30c1912422b28380ed1f53 /pkg/tcpip/tcpip_test.go | |
parent | f37ace6661dfed8acae7e22ed0eb9ad78bdeab34 (diff) |
Remove count argument from tcpip.Endpoint.Read
The same intent can be specified via the io.Writer.
PiperOrigin-RevId: 352098747
Diffstat (limited to 'pkg/tcpip/tcpip_test.go')
-rw-r--r-- | pkg/tcpip/tcpip_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/tcpip/tcpip_test.go b/pkg/tcpip/tcpip_test.go index 9bd563c46..269081ff8 100644 --- a/pkg/tcpip/tcpip_test.go +++ b/pkg/tcpip/tcpip_test.go @@ -15,12 +15,46 @@ package tcpip import ( + "bytes" "fmt" + "io" "net" "strings" "testing" + + "github.com/google/go-cmp/cmp" ) +func TestLimitedWriter_Write(t *testing.T) { + var b bytes.Buffer + l := LimitedWriter{ + W: &b, + N: 5, + } + if n, err := l.Write([]byte{0, 1, 2}); err != nil { + t.Errorf("got l.Write(3/5) = (_, %s), want nil", err) + } else if n != 3 { + t.Errorf("got l.Write(3/5) = (%d, _), want 3", n) + } + if n, err := l.Write([]byte{3, 4, 5}); err != io.ErrShortWrite { + t.Errorf("got l.Write(3/2) = (_, %s), want io.ErrShortWrite", err) + } else if n != 2 { + t.Errorf("got l.Write(3/2) = (%d, _), want 2", n) + } + if l.N != 0 { + t.Errorf("got l.N = %d, want 0", l.N) + } + l.N = 1 + if n, err := l.Write([]byte{5}); err != nil { + t.Errorf("got l.Write(1/1) = (_, %s), want nil", err) + } else if n != 1 { + t.Errorf("got l.Write(1/1) = (%d, _), want 1", n) + } + if diff := cmp.Diff(b.Bytes(), []byte{0, 1, 2, 3, 4, 5}); diff != "" { + t.Errorf("%T wrote incorrect data: (-want +got):\n%s", l, diff) + } +} + func TestSubnetContains(t *testing.T) { tests := []struct { s Address |