Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gzip support #1

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ jobs:
uses: ./
with:
entrypoint: example/stub-subfolders/entrypoint.sh
- name: Run gzip example
uses: ./
with:
entrypoint: example/simple-with-gzip/entrypoint.sh
44 changes: 44 additions & 0 deletions example/simple-with-gzip/client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"
"log"
"os"
"time"

pb "github.com/tokopedia/gripmock/protogen/example/simple-with-gzip"
"google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

c := pb.NewGripmockClient(conn)

// Contact the server and print out its response.
name := "tokopedia"
if len(os.Args) > 1 {
name = os.Args[1]
}
r, err := c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.UseCompressor(gzip.Name))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode)

name = "world"
r, err = c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.UseCompressor(gzip.Name))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode)
}
10 changes: 10 additions & 0 deletions example/simple-with-gzip/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

# this file is used by .github/workflows/integration-test.yml

gripmock --stub=example/simple-with-gzip/stub example/simple-with-gzip/simple-with-gzip.proto &

# wait for generated files to be available and gripmock is up
sleep 2

go run example/simple-with-gzip/client/*.go
23 changes: 23 additions & 0 deletions example/simple-with-gzip/simple-with-gzip.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";
option go_package = "github.com/tokopedia/gripmock/protogen/data/protogen/example/simple-with-gzip";

package simple_with_gzip;



// The Gripmock service definition.
service Gripmock {
// simple unary method
rpc SayHello (Request) returns (Reply);
}

// The request message containing the user's name.
message Request {
string name = 1;
}

// The response message containing the greetings
message Reply {
string message = 1;
int32 return_code = 2;
}
32 changes: 32 additions & 0 deletions example/simple-with-gzip/stub/simple-with-gzip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"service": "Gripmock",
"method": "SayHello",
"input": {
"equals": {
"name": "tokopedia"
}
},
"output": {
"data": {
"message": "Hello Tokopedia",
"return_code": 1
}
}
},
{
"service": "Gripmock",
"method": "SayHello",
"input": {
"equals": {
"name": "world"
}
},
"output": {
"data": {
"message": "Hello World",
"return_code": 1
}
}
}
]
1 change: 1 addition & 0 deletions protoc-gen-gripmock/server.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"golang.org/x/net/context"
"google.golang.org/grpc"
_ "google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/runtime/protoiface"
)
Expand Down
Loading