Skip to content

Commit

Permalink
Add test for bytes type field
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 9, 2024
1 parent 4712365 commit b727251
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 18 deletions.
21 changes: 21 additions & 0 deletions grpcstub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,27 @@ func TestResponseAny(t *testing.T) {
}
}

func TestResponseAnyFields(t *testing.T) {
ctx := context.Background()
ts := NewServer(t, "testdata/hello.proto")
t.Cleanup(func() {
ts.Close()
})
ts.Service("hello.GrpcTestService").Method("HelloFields").ResponseString(`{"field_bytes": "aGVsbG8="}`) // Base64 encoding to pass bytes type

client := hello.NewGrpcTestServiceClient(ts.Conn())
res, err := client.HelloFields(ctx, &hello.HelloFieldsRequest{
FieldBytes: []byte("hello"),
})
if err != nil {
t.Fatal(err)
}
got := res.FieldBytes
if want := "hello"; string(got) != want {
t.Errorf("got %v\nwant %v", got, want)
}
}

func TestBufProtoRegistry(t *testing.T) {
t.Run("Use buf.lock", func(t *testing.T) {
ts := NewServer(t, "testdata/bsr/protobuf/pinger/pinger.proto", BufLock("testdata/bsr/protobuf/buf.lock"))
Expand Down
9 changes: 9 additions & 0 deletions testdata/hello.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package hello;

service GrpcTestService {
rpc Hello (HelloRequest) returns (HelloResponse);
rpc HelloFields (HelloFieldsRequest) returns (HelloFieldsResponse);
}

message HelloRequest {
Expand All @@ -29,3 +30,11 @@ message HelloResponse {

google.protobuf.Timestamp create_time = 5;
}

message HelloFieldsRequest {
bytes field_bytes = 1;
}

message HelloFieldsResponse {
bytes field_bytes = 1;
}
160 changes: 147 additions & 13 deletions testdata/hello/hello.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions testdata/hello/hello_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions testdata/routeguide/route_guide.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testdata/routeguide/route_guide_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b727251

Please sign in to comment.