Skip to content

Commit

Permalink
prettify xtest grpc stream msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed May 2, 2024
1 parent f887b4d commit f89ee3b
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions internal/xtest/grpclogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ func (l GrpcLogger) UnaryClientInterceptor(
opts ...grpc.CallOption,
) error {
err := invoker(ctx, method, req, reply, cc, opts...)
l.t.Logf(
"UnaryClientInterceptor: %s - err: %v\n\nreq:\n%v\n\nresp:\n%v",
method,
err,
req,
reply,
)
if err != nil {
l.t.Logf("UnaryClientInterceptor: %s - err: %v\n\nreq:\n%v\n\nresp:\n%v", method, err, req, reply)
} else {
l.t.Logf("UnaryClientInterceptor: %s : %v\n\nreq:\n%v\n\nresp:\n%v", method, req, reply)

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: (testing.TB).Logf format %v reads arg #4, but call has 3 args (govet)

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, ubuntu)

(testing.TB).Logf format %v reads arg #4, but call has 3 args

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, macOS)

(testing.TB).Logf format %v reads arg #4, but call has 3 args

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, windows)

(testing.TB).Logf format %v reads arg #4, but call has 3 args

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, ubuntu)

(testing.TB).Logf format %v reads arg #4, but call has 3 args

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, macOS)

(testing.TB).Logf format %v reads arg #4, but call has 3 args

Check failure on line 41 in internal/xtest/grpclogger.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, windows)

(testing.TB).Logf format %v reads arg #4, but call has 3 args
}

return err
}
Expand All @@ -59,12 +57,11 @@ func (l GrpcLogger) StreamClientInterceptor(
if stream != nil {
stream = streamWrapper
}
l.t.Logf(
"StreamStart: %v with err '%v' (streamID: %v)",
method,
err,
streamWrapper.streamID,
)
if err != nil {
l.t.Logf("StreamStart: %v with err '%v' (streamID: %v)", method, err, streamWrapper.streamID)
} else {
l.t.Logf("StreamStart: %v (streamID: %v)", method, streamWrapper.streamID)
}

return stream, err
}
Expand All @@ -81,21 +78,33 @@ func newGrpcLoggerStream(stream grpc.ClientStream, t testing.TB) grpcLoggerStrea

func (g grpcLoggerStream) CloseSend() error {
err := g.ClientStream.CloseSend()
g.t.Logf("CloseSend: %v (streamID: %v)", err, g.streamID)
if err != nil {
g.t.Logf("CloseSend: %v (streamID: %v)", err, g.streamID)
} else {
g.t.Logf("CloseSend (streamID: %v)", g.streamID)
}

return err
}

func (g grpcLoggerStream) SendMsg(m interface{}) error {
err := g.ClientStream.SendMsg(m)
g.t.Logf("SendMsg (streamID: %v) with err '%v':\n%v ", g.streamID, err, m)
if err != nil {
g.t.Logf("SendMsg (streamID: %v) with err '%v':\n%v ", g.streamID, err, m)
} else {
g.t.Logf("SendMsg (streamID: %v):\n%v ", g.streamID, m)
}

return err
}

func (g grpcLoggerStream) RecvMsg(m interface{}) error {
err := g.ClientStream.RecvMsg(m)
g.t.Logf("RecvMsg (streamID: %v) with err '%v':\n%v ", g.streamID, err, m)
if err != nil {
g.t.Logf("RecvMsg (streamID: %v) with err '%v':\n%v ", g.streamID, err, m)
} else {
g.t.Logf("RecvMsg (streamID: %v):\n%v ", g.streamID, m)
}

return err
}

0 comments on commit f89ee3b

Please sign in to comment.