Skip to content

Commit

Permalink
Merge pull request #18 from daulet/master
Browse files Browse the repository at this point in the history
Better formatting of FprintReader output
  • Loading branch information
jba authored Oct 16, 2022
2 parents 3f199e6 + 7d9b72d commit 5c964d3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
5 changes: 1 addition & 4 deletions grpcreplay/grpcreplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,7 @@ func FprintReader(w io.Writer, r io.Reader) error {
switch {
case e.msg.msg != nil:
fmt.Fprintf(w, ", message:\n")
buf, err := prototext.Marshal(e.msg.msg)
if err != nil {
return err
}
buf := []byte(prototext.Format(e.msg.msg))
if _, err := w.Write(buf); err != nil {
return err
}
Expand Down
17 changes: 17 additions & 0 deletions grpcreplay/grpcreplay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"errors"
"io"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -619,3 +620,19 @@ func TestOutOfOrderStreamReplay(t *testing.T) {
buf = record(t, func(t *testing.T, conn *grpc.ClientConn) { run(t, conn, 1, 2) })
replay(t, buf, func(t *testing.T, conn *grpc.ClientConn) { run(t, conn, 2, 1) })
}

func TestFprintReader(t *testing.T) {
buf := record(t, testService)
got := &bytes.Buffer{}
err := FprintReader(got, buf)
if err != nil {
t.Fatal(err)
}
want, err := os.ReadFile("testdata/fprint.txt")
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got.Bytes(), want) {
t.Errorf("got:\n%v\nwant:\n%v\n", got.String(), string(want))
}
}
42 changes: 42 additions & 0 deletions grpcreplay/testdata/fprint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
initial state: "\x01\x02\x03"
#1: kind: REQUEST, method: /intstore.IntStore/Set, ref index: 0, message:
name: "a"
value: 1
#2: kind: RESPONSE, method: , ref index: 1, message:
#3: kind: REQUEST, method: /intstore.IntStore/Get, ref index: 0, message:
name: "a"
#4: kind: RESPONSE, method: , ref index: 3, message:
name: "a"
value: 1
#5: kind: REQUEST, method: /intstore.IntStore/Get, ref index: 0, message:
name: "x"
#6: kind: RESPONSE, method: , ref index: 5, error: rpc error: code = NotFound desc = "x"
#7: kind: CREATE_STREAM, method: /intstore.IntStore/ListItems, ref index: 0
#8: kind: SEND, method: , ref index: 7, message:
#9: kind: RECV, method: , ref index: 7, message:
name: "a"
value: 1
#10: kind: RECV, method: , ref index: 7, error: EOF
#11: kind: CREATE_STREAM, method: /intstore.IntStore/SetStream, ref index: 0
#12: kind: SEND, method: , ref index: 11, message:
name: "b"
value: 2
#13: kind: SEND, method: , ref index: 11, message:
name: "c"
value: 3
#14: kind: RECV, method: , ref index: 11, message:
count: 2
#15: kind: CREATE_STREAM, method: /intstore.IntStore/StreamChat, ref index: 0
#16: kind: SEND, method: , ref index: 15, message:
name: "d"
value: 4
#17: kind: RECV, method: , ref index: 15, message:
name: "d"
value: 4
#18: kind: SEND, method: , ref index: 15, message:
name: "e"
value: 5
#19: kind: RECV, method: , ref index: 15, message:
name: "e"
value: 5
#20: kind: RECV, method: , ref index: 15, error: EOF

0 comments on commit 5c964d3

Please sign in to comment.