Skip to content

Commit

Permalink
Review comments - use more mocks; replace gomock.Any()
Browse files Browse the repository at this point in the history
  • Loading branch information
witriew committed Aug 25, 2021
1 parent 614aa04 commit 9445a06
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions encoding/thrift/inbound_nowire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package thrift
import (
"context"
"fmt"
"io"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -49,14 +48,6 @@ func (br *bodyReader) Decode(sr stream.Reader) error {
return br.err
}

type responseWriter struct{ err error }

var _ stream.ResponseWriter = (*responseWriter)(nil)

func (rw responseWriter) WriteResponse(wire.EnvelopeType, io.Writer, stream.Enveloper) error {
return rw.err
}

type responseHandler struct {
t *testing.T
nwc *NoWireCall
Expand Down Expand Up @@ -179,11 +170,16 @@ func TestNoWireHandleWriteResponseError(t *testing.T) {
env := streamtest.NewMockEnveloper(mockCtrl)
env.EXPECT().EnvelopeType().Return(wire.Reply).Times(1)

proto := streamtest.NewMockRequestReader(mockCtrl)
proto.EXPECT().ReadRequest(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(responseWriter{err: fmt.Errorf("write response error")}, nil)
rw := new(transporttest.FakeResponseWriter)
streamRw := streamtest.NewMockResponseWriter(mockCtrl)
streamRw.EXPECT().WriteResponse(wire.Reply, rw, env).Return(fmt.Errorf("write response error")).Times(1)

req := request()
br := &bodyReader{}
proto := streamtest.NewMockRequestReader(mockCtrl)
proto.EXPECT().ReadRequest(gomock.Any(), wire.Call, req.Body, br).
Return(streamRw, nil)

rh := responseHandler{t: t, reqBody: br, body: env}
h := thriftNoWireHandler{
Handler: &rh,
Expand All @@ -193,8 +189,6 @@ func TestNoWireHandleWriteResponseError(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testtime.Second)
defer cancel()

req := request()
rw := new(transporttest.FakeResponseWriter)
err := h.Handle(ctx, req, rw)
require.Error(t, err)
assert.Contains(t, err.Error(), "write response error")
Expand Down

0 comments on commit 9445a06

Please sign in to comment.