summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/transport_test.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-01-22 12:24:20 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-22 12:26:09 -0800
commit6c0e1d9cfe6adbfbb32e7020d6426608ac63ad37 (patch)
tree3ddb770b9965ccfcdb6ecb73062e2d466c379439 /pkg/tcpip/stack/transport_test.go
parent527ef5fc0307102fa7cc0b32bcc2eb8cca3e21a8 (diff)
Define tcpip.Payloader in terms of io.Reader
Fixes #1509. PiperOrigin-RevId: 353295589
Diffstat (limited to 'pkg/tcpip/stack/transport_test.go')
-rw-r--r--pkg/tcpip/stack/transport_test.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/tcpip/stack/transport_test.go b/pkg/tcpip/stack/transport_test.go
index 9d39533a1..dbf8b4db1 100644
--- a/pkg/tcpip/stack/transport_test.go
+++ b/pkg/tcpip/stack/transport_test.go
@@ -15,6 +15,7 @@
package stack_test
import (
+ "bytes"
"io"
"testing"
@@ -95,10 +96,11 @@ func (f *fakeTransportEndpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions
return 0, tcpip.ErrNoRoute
}
- v, err := p.FullPayload()
- if err != nil {
- return 0, err
+ v := make([]byte, p.Len())
+ if _, err := io.ReadFull(p, v); err != nil {
+ return 0, tcpip.ErrBadBuffer
}
+
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
ReserveHeaderBytes: int(f.route.MaxHeaderLength()) + fakeTransHeaderLen,
Data: buffer.View(v).ToVectorisedView(),
@@ -520,8 +522,10 @@ func TestTransportSend(t *testing.T) {
}
// Create buffer that will hold the payload.
- view := buffer.NewView(30)
- if _, err := ep.Write(tcpip.SlicePayload(view), tcpip.WriteOptions{}); err != nil {
+ b := make([]byte, 30)
+ var r bytes.Reader
+ r.Reset(b)
+ if _, err := ep.Write(&r, tcpip.WriteOptions{}); err != nil {
t.Fatalf("write failed: %v", err)
}