Skip to content

Commit 5d6ce86

Browse files
authored
feat: gzip support (#1)
* gzip support with example and integration test
1 parent 7a3c15c commit 5d6ce86

8 files changed

Lines changed: 451 additions & 0 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ jobs:
4242
uses: ./
4343
with:
4444
entrypoint: example/stub-subfolders/entrypoint.sh
45+
- name: Run gzip example
46+
uses: ./
47+
with:
48+
entrypoint: example/simple-with-gzip/entrypoint.sh
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"os"
7+
"time"
8+
9+
pb "github.com/tokopedia/gripmock/protogen/example/simple-with-gzip"
10+
"google.golang.org/grpc"
11+
"google.golang.org/grpc/encoding/gzip"
12+
)
13+
14+
func main() {
15+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
16+
defer cancel()
17+
18+
// Set up a connection to the server.
19+
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithInsecure(), grpc.WithBlock())
20+
if err != nil {
21+
log.Fatalf("did not connect: %v", err)
22+
}
23+
defer conn.Close()
24+
25+
c := pb.NewGripmockClient(conn)
26+
27+
// Contact the server and print out its response.
28+
name := "tokopedia"
29+
if len(os.Args) > 1 {
30+
name = os.Args[1]
31+
}
32+
r, err := c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.UseCompressor(gzip.Name))
33+
if err != nil {
34+
log.Fatalf("error from grpc: %v", err)
35+
}
36+
log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode)
37+
38+
name = "world"
39+
r, err = c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.UseCompressor(gzip.Name))
40+
if err != nil {
41+
log.Fatalf("error from grpc: %v", err)
42+
}
43+
log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode)
44+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
# this file is used by .github/workflows/integration-test.yml
4+
5+
gripmock --stub=example/simple-with-gzip/stub example/simple-with-gzip/simple-with-gzip.proto &
6+
7+
# wait for generated files to be available and gripmock is up
8+
sleep 2
9+
10+
go run example/simple-with-gzip/client/*.go
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
syntax = "proto3";
2+
option go_package = "github.com/tokopedia/gripmock/protogen/data/protogen/example/simple-with-gzip";
3+
4+
package simple_with_gzip;
5+
6+
7+
8+
// The Gripmock service definition.
9+
service Gripmock {
10+
// simple unary method
11+
rpc SayHello (Request) returns (Reply);
12+
}
13+
14+
// The request message containing the user's name.
15+
message Request {
16+
string name = 1;
17+
}
18+
19+
// The response message containing the greetings
20+
message Reply {
21+
string message = 1;
22+
int32 return_code = 2;
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"service": "Gripmock",
4+
"method": "SayHello",
5+
"input": {
6+
"equals": {
7+
"name": "tokopedia"
8+
}
9+
},
10+
"output": {
11+
"data": {
12+
"message": "Hello Tokopedia",
13+
"return_code": 1
14+
}
15+
}
16+
},
17+
{
18+
"service": "Gripmock",
19+
"method": "SayHello",
20+
"input": {
21+
"equals": {
22+
"name": "world"
23+
}
24+
},
25+
"output": {
26+
"data": {
27+
"message": "Hello World",
28+
"return_code": 1
29+
}
30+
}
31+
}
32+
]

protoc-gen-gripmock/server.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/golang/protobuf/jsonpb"
1515
"golang.org/x/net/context"
1616
"google.golang.org/grpc"
17+
_ "google.golang.org/grpc/encoding/gzip"
1718
"google.golang.org/grpc/reflection"
1819
"google.golang.org/protobuf/runtime/protoiface"
1920
)

0 commit comments

Comments
 (0)