commit 5347d025110627cf4f2631434534790ca3b33651 Author: David Fifield david@bamsoftware.com Date: Tue Mar 5 14:42:12 2019 -0700
Refactor testExtOrPortSetMetadataIndividual. --- pt_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/pt_test.go b/pt_test.go index ce26b16..15907ef 100644 --- a/pt_test.go +++ b/pt_test.go @@ -706,13 +706,16 @@ func TestExtOrPortRecvCommand(t *testing.T) {
// set up so that extOrPortSetMetadata can write to one buffer and read from another. type mockSetMetadataBuf struct { - bytes.Buffer - ReadBuf bytes.Buffer + ReadBuf bytes.Buffer + WriteBuf bytes.Buffer }
func (buf *mockSetMetadataBuf) Read(p []byte) (int, error) { - n, err := buf.ReadBuf.Read(p) - return n, err + return buf.ReadBuf.Read(p) +} + +func (buf *mockSetMetadataBuf) Write(p []byte) (int, error) { + return buf.WriteBuf.Write(p) }
func testExtOrPortSetMetadataIndividual(t *testing.T, addr, methodName string) { @@ -721,14 +724,14 @@ func testExtOrPortSetMetadataIndividual(t *testing.T, addr, methodName string) { // fake an OKAY response. err = extOrPortSendCommand(&buf.ReadBuf, extOrCmdOkay, []byte{}) if err != nil { - t.Fatal(err) + panic(err) } err = extOrPortSetMetadata(&buf, addr, methodName) if err != nil { t.Fatalf("error in extOrPortSetMetadata: %s", err) } for { - cmd, body, err := extOrPortRecvCommand(&buf.Buffer) + cmd, body, err := extOrPortRecvCommand(&buf.WriteBuf) if err != nil { t.Fatalf("error in extOrPortRecvCommand: %s", err) }
tor-commits@lists.torproject.org