Skip to content
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 @@ -55,3 +55,7 @@ jobs:

- name: Run stub subfolders example
run: docker run --rm --entrypoint example/stub-subfolders/entrypoint.sh gripmock:test
- 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/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/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/metadata"
Expand Down
Loading