From c4e4a941f378eef6a3f9498c9280d491b61aabf5 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Fri, 13 Sep 2019 16:07:30 +0700 Subject: [PATCH 01/17] add action --- .github/workflows/integration-test.yml | 15 +++++++++++++++ test/example/entrypoint.sh | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 .github/workflows/integration-test.yml create mode 100755 test/example/entrypoint.sh diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 00000000..3e62ef42 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,15 @@ +name: Integration test +on: push + +jobs: + build: + name: Run example + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + - name: Test example + uses: ./ + with: + entrypoint: test/example/entrypoint.sh + diff --git a/test/example/entrypoint.sh b/test/example/entrypoint.sh new file mode 100755 index 00000000..de698f77 --- /dev/null +++ b/test/example/entrypoint.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +gripmock --stub=example/stubs example/pb/hello.proto & + +go run example/client/go/*.go \ No newline at end of file From f2113f6cd8e199782137108f59883621f02777be Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 17:11:05 +0700 Subject: [PATCH 02/17] add grpc listen --- test/example/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/example/entrypoint.sh b/test/example/entrypoint.sh index de698f77..ecd3b3b0 100755 --- a/test/example/entrypoint.sh +++ b/test/example/entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -gripmock --stub=example/stubs example/pb/hello.proto & +gripmock --grpc-listen='0.0.0.0' --stub=example/stubs example/pb/hello.proto & go run example/client/go/*.go \ No newline at end of file From b1d1d04d48d7de2539e821d7a9fb980458312d99 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 17:26:52 +0700 Subject: [PATCH 03/17] only run --- build.sh | 2 +- test/example/entrypoint.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 23beb438..91dd9f0d 100755 --- a/build.sh +++ b/build.sh @@ -7,4 +7,4 @@ fi go build ../. -docker build -t "ahmadmuzakki/gripmock:$1" . \ No newline at end of file +docker build -t "tkpd/gripmock:$1" . \ No newline at end of file diff --git a/test/example/entrypoint.sh b/test/example/entrypoint.sh index ecd3b3b0..5b6cbab1 100755 --- a/test/example/entrypoint.sh +++ b/test/example/entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -gripmock --grpc-listen='0.0.0.0' --stub=example/stubs example/pb/hello.proto & +gripmock --grpc-listen='0.0.0.0' --stub=example/stubs example/pb/hello.proto -go run example/client/go/*.go \ No newline at end of file +#go run example/client/go/*.go \ No newline at end of file From 27d52e789747263ca39d7688b4b47871fa33e563 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 17:28:21 +0700 Subject: [PATCH 04/17] using gripmock:test --- .github/workflows/integration-test.yml | 2 +- gripmock.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 3e62ef42..6950dacf 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -9,7 +9,7 @@ jobs: - name: Checkout uses: actions/checkout@master - name: Test example - uses: ./ + uses: tkpd/gripmock:test with: entrypoint: test/example/entrypoint.sh diff --git a/gripmock.go b/gripmock.go index 6aaf49fb..5ee625cf 100644 --- a/gripmock.go +++ b/gripmock.go @@ -20,6 +20,7 @@ func main() { adminport := flag.String("admin-port", "4771", "Port of stub admin server") adminBindAddr := flag.String("admin-listen", "", "Adress the admin server will bind to. Default to localhost, set to 0.0.0.0 to use from another machine") stubPath := flag.String("stub", "", "Path where the stub files are (Optional)") + wktDir := flag.String("wkt-dir", "/protobuf", "Directory of well-known-types protos.") // for backwards compatibility if os.Args[1] == "gripmock" { os.Args = append(os.Args[:1], os.Args[2:]...) @@ -63,6 +64,7 @@ func main() { grpcAddress: *grpcBindAddr, grpcPort: *grpcPort, output: output, + wktPath: *wktDir, }) // build the server @@ -94,6 +96,7 @@ type protocParam struct { grpcAddress string grpcPort string output string + wktPath string } func generateProtoc(param protocParam) { @@ -105,7 +108,7 @@ func generateProtoc(param protocParam) { args := []string{"-I", protodir} // include well-known-types - args = append(args, "-I", "/protobuf") + args = append(args, "-I", param.wktPath) args = append(args, param.protoPath...) args = append(args, "--go_out=plugins=grpc:"+param.output) args = append(args, fmt.Sprintf("--gripmock_out=admin-port=%s,grpc-address=%s,grpc-port=%s:%s", From 1a214b1e698eb9b7d37bc5897eb699e94a3521ff Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 17:29:48 +0700 Subject: [PATCH 05/17] using gripmock:test --- .github/workflows/integration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 6950dacf..4ae730fd 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -9,7 +9,7 @@ jobs: - name: Checkout uses: actions/checkout@master - name: Test example - uses: tkpd/gripmock:test + uses: docker://tkpd/gripmock:test with: entrypoint: test/example/entrypoint.sh From aecc59f52e73c47257d90b3524fa554bb902634d Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 17:32:36 +0700 Subject: [PATCH 06/17] wait for it to serve --- test/example/entrypoint.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/example/entrypoint.sh b/test/example/entrypoint.sh index 5b6cbab1..23cecffa 100755 --- a/test/example/entrypoint.sh +++ b/test/example/entrypoint.sh @@ -1,5 +1,7 @@ #!/usr/bin/env sh -gripmock --grpc-listen='0.0.0.0' --stub=example/stubs example/pb/hello.proto +gripmock --stub=example/stubs example/pb/hello.proto & -#go run example/client/go/*.go \ No newline at end of file +sleep 5 + +go run example/client/go/*.go \ No newline at end of file From bdca9196df7df7684342807ad7f513ff6103d59b Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 18:19:30 +0700 Subject: [PATCH 07/17] test example 2 --- .github/workflows/integration-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 4ae730fd..a5f6d85c 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -9,7 +9,11 @@ jobs: - name: Checkout uses: actions/checkout@master - name: Test example - uses: docker://tkpd/gripmock:test + uses: ./ + with: + entrypoint: test/example/entrypoint.sh + - name: Test example 2 + uses: ./ with: entrypoint: test/example/entrypoint.sh From 13e82e694e0d3d42ea9d0ec814e9c45265311d0b Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 18:46:35 +0700 Subject: [PATCH 08/17] run simple example --- .github/workflows/integration-test.yml | 8 +- .github/workflows/run-example.sh | 5 + example/simple/client/main.go | 36 +++++ example/simple/simple.pb.go | 196 +++++++++++++++++++++++++ example/simple/simple.proto | 19 +++ example/simple/stub/simple.json | 14 ++ test/example/entrypoint.sh | 7 - 7 files changed, 272 insertions(+), 13 deletions(-) create mode 100755 .github/workflows/run-example.sh create mode 100644 example/simple/client/main.go create mode 100644 example/simple/simple.pb.go create mode 100644 example/simple/simple.proto create mode 100644 example/simple/stub/simple.json delete mode 100755 test/example/entrypoint.sh diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index a5f6d85c..a87a19b1 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -8,12 +8,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@master - - name: Test example + - name: Run Simple Example uses: ./ with: - entrypoint: test/example/entrypoint.sh - - name: Test example 2 - uses: ./ - with: - entrypoint: test/example/entrypoint.sh + entrypoint: .github/workflows/run-example.sh simple diff --git a/.github/workflows/run-example.sh b/.github/workflows/run-example.sh new file mode 100755 index 00000000..43453e4f --- /dev/null +++ b/.github/workflows/run-example.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +gripmock --stub=example/$1/stub example/$1/$1.proto & + +go run example/$1/client/*.go \ No newline at end of file diff --git a/example/simple/client/main.go b/example/simple/client/main.go new file mode 100644 index 00000000..2c6e8f96 --- /dev/null +++ b/example/simple/client/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "context" + "log" + "os" + "time" + + pb "github.com/tokopedia/gripmock/example/simple" + "google.golang.org/grpc" +) + +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.NewSimpleClient(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}) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + log.Printf("Greeting: %s", r.Message) +} diff --git a/example/simple/simple.pb.go b/example/simple/simple.pb.go new file mode 100644 index 00000000..e30768b9 --- /dev/null +++ b/example/simple/simple.pb.go @@ -0,0 +1,196 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: simple.proto + +package simple + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +// The request message containing the user's name. +type Request struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request) Reset() { *m = Request{} } +func (m *Request) String() string { return proto.CompactTextString(m) } +func (*Request) ProtoMessage() {} +func (*Request) Descriptor() ([]byte, []int) { + return fileDescriptor_simple_7ef306436b49ce3d, []int{0} +} +func (m *Request) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request.Unmarshal(m, b) +} +func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request.Marshal(b, m, deterministic) +} +func (dst *Request) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request.Merge(dst, src) +} +func (m *Request) XXX_Size() int { + return xxx_messageInfo_Request.Size(m) +} +func (m *Request) XXX_DiscardUnknown() { + xxx_messageInfo_Request.DiscardUnknown(m) +} + +var xxx_messageInfo_Request proto.InternalMessageInfo + +func (m *Request) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// The response message containing the greetings +type Reply struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Reply) Reset() { *m = Reply{} } +func (m *Reply) String() string { return proto.CompactTextString(m) } +func (*Reply) ProtoMessage() {} +func (*Reply) Descriptor() ([]byte, []int) { + return fileDescriptor_simple_7ef306436b49ce3d, []int{1} +} +func (m *Reply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Reply.Unmarshal(m, b) +} +func (m *Reply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Reply.Marshal(b, m, deterministic) +} +func (dst *Reply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Reply.Merge(dst, src) +} +func (m *Reply) XXX_Size() int { + return xxx_messageInfo_Reply.Size(m) +} +func (m *Reply) XXX_DiscardUnknown() { + xxx_messageInfo_Reply.DiscardUnknown(m) +} + +var xxx_messageInfo_Reply proto.InternalMessageInfo + +func (m *Reply) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +func init() { + proto.RegisterType((*Request)(nil), "simple.Request") + proto.RegisterType((*Reply)(nil), "simple.Reply") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// SimpleClient is the client API for Simple service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type SimpleClient interface { + // simple unary method + SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) +} + +type simpleClient struct { + cc *grpc.ClientConn +} + +func NewSimpleClient(cc *grpc.ClientConn) SimpleClient { + return &simpleClient{cc} +} + +func (c *simpleClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { + out := new(Reply) + err := c.cc.Invoke(ctx, "/simple.Simple/SayHello", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SimpleServer is the server API for Simple service. +type SimpleServer interface { + // simple unary method + SayHello(context.Context, *Request) (*Reply, error) +} + +func RegisterSimpleServer(s *grpc.Server, srv SimpleServer) { + s.RegisterService(&_Simple_serviceDesc, srv) +} + +func _Simple_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SimpleServer).SayHello(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/simple.Simple/SayHello", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SimpleServer).SayHello(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + +var _Simple_serviceDesc = grpc.ServiceDesc{ + ServiceName: "simple.Simple", + HandlerType: (*SimpleServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SayHello", + Handler: _Simple_SayHello_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "simple.proto", +} + +func init() { proto.RegisterFile("simple.proto", fileDescriptor_simple_7ef306436b49ce3d) } + +var fileDescriptor_simple_7ef306436b49ce3d = []byte{ + // 131 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0xce, 0xcc, 0x2d, + 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0xd8, + 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, + 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x45, 0x2e, 0xd6, 0xa0, 0xd4, 0x82, 0x9c, + 0x4a, 0x21, 0x09, 0x2e, 0xf6, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0x74, 0x98, 0x3c, 0x8c, 0x6b, 0x64, + 0xc2, 0xc5, 0x16, 0x0c, 0x36, 0x4b, 0x48, 0x8b, 0x8b, 0x23, 0x38, 0xb1, 0xd2, 0x23, 0x35, 0x27, + 0x27, 0x5f, 0x88, 0x5f, 0x0f, 0x6a, 0x1d, 0xd4, 0x74, 0x29, 0x5e, 0x84, 0x40, 0x41, 0x4e, 0x65, + 0x12, 0x1b, 0xd8, 0x19, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x19, 0x8a, 0x14, 0x59, 0x96, + 0x00, 0x00, 0x00, +} diff --git a/example/simple/simple.proto b/example/simple/simple.proto new file mode 100644 index 00000000..84c3a914 --- /dev/null +++ b/example/simple/simple.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package simple; + +// The greeting service definition. +service Simple { + // 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; +} \ No newline at end of file diff --git a/example/simple/stub/simple.json b/example/simple/stub/simple.json new file mode 100644 index 00000000..61c12fda --- /dev/null +++ b/example/simple/stub/simple.json @@ -0,0 +1,14 @@ +{ + "service":"Simple", + "method":"SayHello", + "input":{ + "equals":{ + "name":"tokopedia" + } + }, + "output":{ + "data":{ + "message":"Hello Tokopedia" + } + } +} \ No newline at end of file diff --git a/test/example/entrypoint.sh b/test/example/entrypoint.sh deleted file mode 100755 index 23cecffa..00000000 --- a/test/example/entrypoint.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env sh - -gripmock --stub=example/stubs example/pb/hello.proto & - -sleep 5 - -go run example/client/go/*.go \ No newline at end of file From 24ca8b4fffa1ec0596c23365909428ff91a23490 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 18:53:04 +0700 Subject: [PATCH 09/17] fix args --- .github/workflows/integration-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index a87a19b1..05d1306b 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -11,5 +11,6 @@ jobs: - name: Run Simple Example uses: ./ with: - entrypoint: .github/workflows/run-example.sh simple + entrypoint: .github/workflows/run-example.sh + args: simple From 77f71241a8909c1d0f99bd7966d983484fda19a5 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Mon, 16 Sep 2019 19:04:27 +0700 Subject: [PATCH 10/17] dont remove gripmock --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d2682d3..aaeb380c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,8 +48,6 @@ WORKDIR /go/src/github.com/tokopedia/gripmock # install gripmock RUN go install -v -RUN rm -rf * - EXPOSE 4770 4771 ENTRYPOINT ["gripmock"] \ No newline at end of file From a85872e7f48aabdd0b603b09da6c399eec0d1792 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 16:07:42 +0700 Subject: [PATCH 11/17] wrap ups test --- .github/workflows/integration-test.yml | 5 + example/client/go/hello.pb.go | 440 ------------------ example/server/generated_server.go | 140 ------ example/{client/go => stream/client}/main.go | 34 +- .../hello.pb.go => stream/stream.pb.go} | 98 ++-- .../{pb/hello.proto => stream/stream.proto} | 9 +- .../stub}/bidirectional-stream.json | 0 .../stub}/client2server-stream.json | 0 .../stub}/server2client-stream.json | 0 example/stubs/standard.json | 14 - example/well-known-types/client/main.go | 31 ++ .../stub/wkt.json} | 2 +- .../well-known-types/well-known-types.pb.go | 115 +++++ .../well-known-types/well-known-types.proto | 11 + 14 files changed, 201 insertions(+), 698 deletions(-) delete mode 100644 example/client/go/hello.pb.go delete mode 100644 example/server/generated_server.go rename example/{client/go => stream/client}/main.go (70%) rename example/{server/hello.pb.go => stream/stream.pb.go} (74%) rename example/{pb/hello.proto => stream/stream.proto} (65%) rename example/{stubs => stream/stub}/bidirectional-stream.json (100%) rename example/{stubs => stream/stub}/client2server-stream.json (100%) rename example/{stubs => stream/stub}/server2client-stream.json (100%) delete mode 100644 example/stubs/standard.json create mode 100644 example/well-known-types/client/main.go rename example/{stubs/healthcheck.json => well-known-types/stub/wkt.json} (86%) create mode 100644 example/well-known-types/well-known-types.pb.go create mode 100644 example/well-known-types/well-known-types.proto diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 05d1306b..7984c512 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -13,4 +13,9 @@ jobs: with: entrypoint: .github/workflows/run-example.sh args: simple + - name: Run Stream Example + uses: ./ + with: + entrypoint: .github/workflows/run-example.sh + args: stream diff --git a/example/client/go/hello.pb.go b/example/client/go/hello.pb.go deleted file mode 100644 index f94d04b3..00000000 --- a/example/client/go/hello.pb.go +++ /dev/null @@ -1,440 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: pb/hello.proto - -package main - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import empty "github.com/golang/protobuf/ptypes/empty" -import wrappers "github.com/golang/protobuf/ptypes/wrappers" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -// The request message containing the user's name. -type Request struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_hello_64609aa425866106, []int{0} -} -func (m *Request) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Request.Unmarshal(m, b) -} -func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Request.Marshal(b, m, deterministic) -} -func (dst *Request) XXX_Merge(src proto.Message) { - xxx_messageInfo_Request.Merge(dst, src) -} -func (m *Request) XXX_Size() int { - return xxx_messageInfo_Request.Size(m) -} -func (m *Request) XXX_DiscardUnknown() { - xxx_messageInfo_Request.DiscardUnknown(m) -} - -var xxx_messageInfo_Request proto.InternalMessageInfo - -func (m *Request) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -// The response message containing the greetings -type Reply struct { - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Reply) Reset() { *m = Reply{} } -func (m *Reply) String() string { return proto.CompactTextString(m) } -func (*Reply) ProtoMessage() {} -func (*Reply) Descriptor() ([]byte, []int) { - return fileDescriptor_hello_64609aa425866106, []int{1} -} -func (m *Reply) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Reply.Unmarshal(m, b) -} -func (m *Reply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Reply.Marshal(b, m, deterministic) -} -func (dst *Reply) XXX_Merge(src proto.Message) { - xxx_messageInfo_Reply.Merge(dst, src) -} -func (m *Reply) XXX_Size() int { - return xxx_messageInfo_Reply.Size(m) -} -func (m *Reply) XXX_DiscardUnknown() { - xxx_messageInfo_Reply.DiscardUnknown(m) -} - -var xxx_messageInfo_Reply proto.InternalMessageInfo - -func (m *Reply) GetMessage() string { - if m != nil { - return m.Message - } - return "" -} - -func init() { - proto.RegisterType((*Request)(nil), "main.Request") - proto.RegisterType((*Reply)(nil), "main.Reply") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// GripmockClient is the client API for Gripmock service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type GripmockClient interface { - // standard grpc method - SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) - // server to client sreaming - ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) - // client to server streaming - ClientStream(ctx context.Context, opts ...grpc.CallOption) (Gripmock_ClientStreamClient, error) - // bidirectional streaming - Bidirectional(ctx context.Context, opts ...grpc.CallOption) (Gripmock_BidirectionalClient, error) - // using well-known-type of Empty - HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*wrappers.StringValue, error) -} - -type gripmockClient struct { - cc *grpc.ClientConn -} - -func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { - return &gripmockClient{cc} -} - -func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { - out := new(Reply) - err := c.cc.Invoke(ctx, "/main.Gripmock/SayHello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *gripmockClient) ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[0], "/main.Gripmock/serverStream", opts...) - if err != nil { - return nil, err - } - x := &gripmockServerStreamClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Gripmock_ServerStreamClient interface { - Recv() (*Reply, error) - grpc.ClientStream -} - -type gripmockServerStreamClient struct { - grpc.ClientStream -} - -func (x *gripmockServerStreamClient) Recv() (*Reply, error) { - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *gripmockClient) ClientStream(ctx context.Context, opts ...grpc.CallOption) (Gripmock_ClientStreamClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[1], "/main.Gripmock/clientStream", opts...) - if err != nil { - return nil, err - } - x := &gripmockClientStreamClient{stream} - return x, nil -} - -type Gripmock_ClientStreamClient interface { - Send(*Request) error - CloseAndRecv() (*Reply, error) - grpc.ClientStream -} - -type gripmockClientStreamClient struct { - grpc.ClientStream -} - -func (x *gripmockClientStreamClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *gripmockClientStreamClient) CloseAndRecv() (*Reply, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *gripmockClient) Bidirectional(ctx context.Context, opts ...grpc.CallOption) (Gripmock_BidirectionalClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[2], "/main.Gripmock/bidirectional", opts...) - if err != nil { - return nil, err - } - x := &gripmockBidirectionalClient{stream} - return x, nil -} - -type Gripmock_BidirectionalClient interface { - Send(*Request) error - Recv() (*Reply, error) - grpc.ClientStream -} - -type gripmockBidirectionalClient struct { - grpc.ClientStream -} - -func (x *gripmockBidirectionalClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *gripmockBidirectionalClient) Recv() (*Reply, error) { - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *gripmockClient) HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*wrappers.StringValue, error) { - out := new(wrappers.StringValue) - err := c.cc.Invoke(ctx, "/main.Gripmock/HealthCheck", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// GripmockServer is the server API for Gripmock service. -type GripmockServer interface { - // standard grpc method - SayHello(context.Context, *Request) (*Reply, error) - // server to client sreaming - ServerStream(*Request, Gripmock_ServerStreamServer) error - // client to server streaming - ClientStream(Gripmock_ClientStreamServer) error - // bidirectional streaming - Bidirectional(Gripmock_BidirectionalServer) error - // using well-known-type of Empty - HealthCheck(context.Context, *empty.Empty) (*wrappers.StringValue, error) -} - -func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { - s.RegisterService(&_Gripmock_serviceDesc, srv) -} - -func _Gripmock_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Request) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GripmockServer).SayHello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/main.Gripmock/SayHello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GripmockServer).SayHello(ctx, req.(*Request)) - } - return interceptor(ctx, in, info, handler) -} - -func _Gripmock_ServerStream_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(Request) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(GripmockServer).ServerStream(m, &gripmockServerStreamServer{stream}) -} - -type Gripmock_ServerStreamServer interface { - Send(*Reply) error - grpc.ServerStream -} - -type gripmockServerStreamServer struct { - grpc.ServerStream -} - -func (x *gripmockServerStreamServer) Send(m *Reply) error { - return x.ServerStream.SendMsg(m) -} - -func _Gripmock_ClientStream_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GripmockServer).ClientStream(&gripmockClientStreamServer{stream}) -} - -type Gripmock_ClientStreamServer interface { - SendAndClose(*Reply) error - Recv() (*Request, error) - grpc.ServerStream -} - -type gripmockClientStreamServer struct { - grpc.ServerStream -} - -func (x *gripmockClientStreamServer) SendAndClose(m *Reply) error { - return x.ServerStream.SendMsg(m) -} - -func (x *gripmockClientStreamServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Gripmock_Bidirectional_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GripmockServer).Bidirectional(&gripmockBidirectionalServer{stream}) -} - -type Gripmock_BidirectionalServer interface { - Send(*Reply) error - Recv() (*Request, error) - grpc.ServerStream -} - -type gripmockBidirectionalServer struct { - grpc.ServerStream -} - -func (x *gripmockBidirectionalServer) Send(m *Reply) error { - return x.ServerStream.SendMsg(m) -} - -func (x *gripmockBidirectionalServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _Gripmock_HealthCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(empty.Empty) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GripmockServer).HealthCheck(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/main.Gripmock/HealthCheck", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GripmockServer).HealthCheck(ctx, req.(*empty.Empty)) - } - return interceptor(ctx, in, info, handler) -} - -var _Gripmock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "main.Gripmock", - HandlerType: (*GripmockServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "SayHello", - Handler: _Gripmock_SayHello_Handler, - }, - { - MethodName: "HealthCheck", - Handler: _Gripmock_HealthCheck_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "serverStream", - Handler: _Gripmock_ServerStream_Handler, - ServerStreams: true, - }, - { - StreamName: "clientStream", - Handler: _Gripmock_ClientStream_Handler, - ClientStreams: true, - }, - { - StreamName: "bidirectional", - Handler: _Gripmock_Bidirectional_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "pb/hello.proto", -} - -func init() { proto.RegisterFile("pb/hello.proto", fileDescriptor_hello_64609aa425866106) } - -var fileDescriptor_hello_64609aa425866106 = []byte{ - // 257 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0x4f, 0x4b, 0xc3, 0x40, - 0x14, 0xc4, 0x59, 0xa9, 0xb6, 0xbe, 0x5a, 0x0f, 0x7b, 0x90, 0x12, 0xff, 0xa0, 0x3d, 0x48, 0x0f, - 0xb2, 0x29, 0xfa, 0x11, 0x8a, 0xd8, 0x73, 0x02, 0xde, 0x37, 0xf1, 0x99, 0x2c, 0xdd, 0x7f, 0xee, - 0x6e, 0x94, 0xdc, 0xfd, 0xe0, 0xb2, 0x89, 0xb9, 0x28, 0xa4, 0xb7, 0xf7, 0x66, 0x7e, 0x0c, 0xc3, - 0xc0, 0xb9, 0x2d, 0xd2, 0x1a, 0xa5, 0x34, 0xcc, 0x3a, 0x13, 0x0c, 0x9d, 0x28, 0x2e, 0x74, 0x72, - 0x59, 0x19, 0x53, 0x49, 0x4c, 0x3b, 0xad, 0x68, 0xde, 0x53, 0x54, 0x36, 0xb4, 0x3d, 0x92, 0xdc, - 0xfc, 0x35, 0xbf, 0x1c, 0xb7, 0x16, 0x9d, 0xef, 0xfd, 0xd5, 0x35, 0x4c, 0x33, 0xfc, 0x68, 0xd0, - 0x07, 0x4a, 0x61, 0xa2, 0xb9, 0xc2, 0x25, 0xb9, 0x25, 0xeb, 0xd3, 0xac, 0xbb, 0x57, 0x77, 0x70, - 0x9c, 0xa1, 0x95, 0x2d, 0x5d, 0xc2, 0x54, 0xa1, 0xf7, 0xbc, 0x1a, 0xfc, 0xe1, 0x7d, 0xfc, 0x3e, - 0x82, 0xd9, 0x8b, 0x13, 0x56, 0x99, 0x72, 0x4f, 0xef, 0x61, 0x96, 0xf3, 0x76, 0x17, 0x3b, 0xd2, - 0x05, 0x8b, 0xf5, 0xd8, 0x6f, 0x7c, 0x32, 0x1f, 0xde, 0x18, 0xf7, 0x00, 0x67, 0x1e, 0xdd, 0x27, - 0xba, 0x3c, 0x38, 0xe4, 0x6a, 0x8c, 0xdd, 0x90, 0x48, 0x97, 0x52, 0xa0, 0x0e, 0x87, 0xe9, 0x35, - 0xa1, 0x29, 0x2c, 0x0a, 0xf1, 0x26, 0x1c, 0x96, 0x41, 0x18, 0xcd, 0xe5, 0x38, 0xbe, 0x21, 0x74, - 0x0b, 0xf3, 0x1d, 0x72, 0x19, 0xea, 0x6d, 0x8d, 0xe5, 0x9e, 0x5e, 0xb0, 0x7e, 0x33, 0x36, 0x6c, - 0xc6, 0x9e, 0xe3, 0xa0, 0xc9, 0xd5, 0x3f, 0x3d, 0x0f, 0x4e, 0xe8, 0xea, 0x95, 0xcb, 0x06, 0x8b, - 0x93, 0x4e, 0x7d, 0xfa, 0x09, 0x00, 0x00, 0xff, 0xff, 0x37, 0x73, 0xb5, 0x17, 0xa4, 0x01, 0x00, - 0x00, -} diff --git a/example/server/generated_server.go b/example/server/generated_server.go deleted file mode 100644 index 357796c1..00000000 --- a/example/server/generated_server.go +++ /dev/null @@ -1,140 +0,0 @@ -// Code generated by GripMock. DO NOT EDIT. -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "log" - "net" - "net/http" - - "github.com/mitchellh/mapstructure" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" -) - -const ( - TCP_ADDRESS = "" - HTTP_PORT = ":" -) - -type Gripmock struct{} - -func (s *Gripmock) SayHello(ctx context.Context, in *Request) (*Reply, error) { - out := &Reply{} - err := findStub("Gripmock", "SayHello", in, out) - return out, err -} - -func (s *Gripmock) ServerStream(in *Request, stream Gripmock_ServerStreamServer) error { - out := &Reply{} - err := findStub("Gripmock", "ServerStream", in, out) - if err != nil { - return err - } - - return stream.Send(out) -} - -func (s *Gripmock) ClientStream(stream Gripmock_ClientStreamServer) error { - out := &Reply{} - for { - input, err := stream.Recv() - if err == io.EOF { - return stream.SendAndClose(out) - } - err = findStub("Gripmock", "ClientStream", input, out) - if err != nil { - return err - } - } -} - -func (s *Gripmock) Bidirectional(stream Gripmock_BidirectionalServer) error { - for { - in, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - out := &Reply{} - err = findStub("Gripmock", "Bidirectional", in, out) - if err != nil { - return err - } - - if err := stream.Send(out); err != nil { - return err - } - } -} - -func main() { - lis, err := net.Listen("tcp", TCP_ADDRESS) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - - s := grpc.NewServer() - - RegisterGripmockServer(s, &Gripmock{}) - - reflection.Register(s) - fmt.Println("Serving gRPC on tcp://" + TCP_ADDRESS) - if err := s.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } -} - -type payload struct { - Service string `json:"service"` - Method string `json:"method"` - Data interface{} `json:"data"` -} - -type response struct { - Data interface{} `json:"data"` - Error string `json:"error"` -} - -func findStub(service, method string, in, out interface{}) error { - url := fmt.Sprintf("http://localhost%s/find", HTTP_PORT) - pyl := payload{ - Service: service, - Method: method, - Data: in, - } - byt, err := json.Marshal(pyl) - if err != nil { - return err - } - reader := bytes.NewReader(byt) - resp, err := http.DefaultClient.Post(url, "application/json", reader) - if err != nil { - return fmt.Errorf("Error request to stub server %v", err) - } - - if resp.StatusCode != http.StatusOK { - body, _ := ioutil.ReadAll(resp.Body) - return fmt.Errorf(string(body)) - } - - respRPC := new(response) - err = json.NewDecoder(resp.Body).Decode(respRPC) - if err != nil { - return fmt.Errorf("decoding json response %v", err) - } - - if respRPC.Error != "" { - return fmt.Errorf(respRPC.Error) - } - - return mapstructure.Decode(respRPC.Data, out) -} diff --git a/example/client/go/main.go b/example/stream/client/main.go similarity index 70% rename from example/client/go/main.go rename to example/stream/client/main.go index e22b9bb7..71261cac 100644 --- a/example/client/go/main.go +++ b/example/stream/client/main.go @@ -4,10 +4,9 @@ import ( "context" "io" "log" - "os" "sync" - "github.com/golang/protobuf/ptypes/empty" + pb "github.com/tokopedia/gripmock/example/stream" "google.golang.org/grpc" ) @@ -18,18 +17,7 @@ func main() { log.Fatalf("did not connect: %v", err) } defer conn.Close() - c := 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(), &Request{Name: name}) - if err != nil { - log.Fatalf("error from grpc: %v", err) - } - log.Printf("Greeting: %s", r.Message) + c := pb.NewGripmockClient(conn) wg := &sync.WaitGroup{} wg.Add(1) @@ -43,18 +31,12 @@ func main() { wg.Wait() - ctx := context.Background() - resp, err := c.HealthCheck(ctx, &empty.Empty{}) - if err != nil { - log.Fatalf("error call HealthCheck %v", err) - } - log.Printf("Healthcheck: %s", resp.GetValue()) } // server to client streaming -func serverStream(c GripmockClient, wg *sync.WaitGroup) { +func serverStream(c pb.GripmockClient, wg *sync.WaitGroup) { defer wg.Done() - req := &Request{ + req := &pb.Request{ Name: "server-to-client-streaming", } stream, err := c.ServerStream(context.Background(), req) @@ -77,14 +59,14 @@ func serverStream(c GripmockClient, wg *sync.WaitGroup) { } // client to server streaming -func clientStream(c GripmockClient, wg *sync.WaitGroup) { +func clientStream(c pb.GripmockClient, wg *sync.WaitGroup) { defer wg.Done() stream, err := c.ClientStream(context.Background()) if err != nil { log.Fatalf("c2s error: %v", err) } - requests := []Request{ + requests := []pb.Request{ { Name: "c2s-1", }, { @@ -106,13 +88,13 @@ func clientStream(c GripmockClient, wg *sync.WaitGroup) { } // bidirectional stream -func bidirectionalStream(c GripmockClient, wg *sync.WaitGroup) { +func bidirectionalStream(c pb.GripmockClient, wg *sync.WaitGroup) { stream, err := c.Bidirectional(context.Background()) if err != nil { log.Fatalf("2ds error: %v", err) } - requests := []Request{ + requests := []pb.Request{ { Name: "2ds-message1", }, { diff --git a/example/server/hello.pb.go b/example/stream/stream.pb.go similarity index 74% rename from example/server/hello.pb.go rename to example/stream/stream.pb.go index 8c15ba7e..57d7a7b9 100644 --- a/example/server/hello.pb.go +++ b/example/stream/stream.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: hello.proto +// source: stream.proto -package main +package stream import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -35,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_hello_6f78bf933483ca19, []int{0} + return fileDescriptor_stream_b89e769b981cf265, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -74,7 +74,7 @@ func (m *Reply) Reset() { *m = Reply{} } func (m *Reply) String() string { return proto.CompactTextString(m) } func (*Reply) ProtoMessage() {} func (*Reply) Descriptor() ([]byte, []int) { - return fileDescriptor_hello_6f78bf933483ca19, []int{1} + return fileDescriptor_stream_b89e769b981cf265, []int{1} } func (m *Reply) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Reply.Unmarshal(m, b) @@ -102,8 +102,8 @@ func (m *Reply) GetMessage() string { } func init() { - proto.RegisterType((*Request)(nil), "main.Request") - proto.RegisterType((*Reply)(nil), "main.Reply") + proto.RegisterType((*Request)(nil), "stream.Request") + proto.RegisterType((*Reply)(nil), "stream.Reply") } // Reference imports to suppress errors if they are not otherwise used. @@ -118,8 +118,6 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type GripmockClient interface { - // standard grpc method - SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) // server to client sreaming ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) // client to server streaming @@ -136,17 +134,8 @@ func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { return &gripmockClient{cc} } -func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { - out := new(Reply) - err := c.cc.Invoke(ctx, "/main.Gripmock/SayHello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *gripmockClient) ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[0], "/main.Gripmock/serverStream", opts...) + stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[0], "/stream.Gripmock/serverStream", opts...) if err != nil { return nil, err } @@ -178,7 +167,7 @@ func (x *gripmockServerStreamClient) Recv() (*Reply, error) { } func (c *gripmockClient) ClientStream(ctx context.Context, opts ...grpc.CallOption) (Gripmock_ClientStreamClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[1], "/main.Gripmock/clientStream", opts...) + stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[1], "/stream.Gripmock/clientStream", opts...) if err != nil { return nil, err } @@ -212,7 +201,7 @@ func (x *gripmockClientStreamClient) CloseAndRecv() (*Reply, error) { } func (c *gripmockClient) Bidirectional(ctx context.Context, opts ...grpc.CallOption) (Gripmock_BidirectionalClient, error) { - stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[2], "/main.Gripmock/bidirectional", opts...) + stream, err := c.cc.NewStream(ctx, &_Gripmock_serviceDesc.Streams[2], "/stream.Gripmock/bidirectional", opts...) if err != nil { return nil, err } @@ -244,8 +233,6 @@ func (x *gripmockBidirectionalClient) Recv() (*Reply, error) { // GripmockServer is the server API for Gripmock service. type GripmockServer interface { - // standard grpc method - SayHello(context.Context, *Request) (*Reply, error) // server to client sreaming ServerStream(*Request, Gripmock_ServerStreamServer) error // client to server streaming @@ -258,24 +245,6 @@ func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { s.RegisterService(&_Gripmock_serviceDesc, srv) } -func _Gripmock_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Request) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GripmockServer).SayHello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/main.Gripmock/SayHello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GripmockServer).SayHello(ctx, req.(*Request)) - } - return interceptor(ctx, in, info, handler) -} - func _Gripmock_ServerStream_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(Request) if err := stream.RecvMsg(m); err != nil { @@ -350,14 +319,9 @@ func (x *gripmockBidirectionalServer) Recv() (*Request, error) { } var _Gripmock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "main.Gripmock", + ServiceName: "stream.Gripmock", HandlerType: (*GripmockServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "SayHello", - Handler: _Gripmock_SayHello_Handler, - }, - }, + Methods: []grpc.MethodDesc{}, Streams: []grpc.StreamDesc{ { StreamName: "serverStream", @@ -376,26 +340,22 @@ var _Gripmock_serviceDesc = grpc.ServiceDesc{ ClientStreams: true, }, }, - Metadata: "hello.proto", -} - -func init() { proto.RegisterFile("hello.proto", fileDescriptor_hello_6f78bf933483ca19) } - -var fileDescriptor_hello_6f78bf933483ca19 = []byte{ - // 225 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0xcd, 0x4a, 0x03, 0x31, - 0x14, 0x85, 0x09, 0x54, 0x5b, 0x6f, 0x2d, 0x42, 0x56, 0x45, 0x11, 0xb4, 0x0b, 0xe9, 0x42, 0xe2, - 0xa0, 0x6f, 0xd0, 0x8d, 0x2e, 0x87, 0x99, 0x85, 0xeb, 0x4c, 0xe6, 0x32, 0x06, 0xf3, 0xe7, 0x4d, - 0xfc, 0x99, 0xa7, 0xf3, 0xd5, 0x24, 0xc1, 0xd9, 0x4e, 0x77, 0xe7, 0x70, 0x3f, 0xce, 0xe1, 0x1e, - 0x58, 0xbf, 0xa1, 0x31, 0x5e, 0x04, 0xf2, 0xc9, 0xf3, 0x85, 0x95, 0xda, 0xed, 0xae, 0x61, 0xd9, - 0xe0, 0xc7, 0x27, 0xc6, 0xc4, 0x39, 0x2c, 0x9c, 0xb4, 0xb8, 0x65, 0x37, 0x6c, 0x7f, 0xd6, 0x14, - 0xbd, 0xbb, 0x85, 0x93, 0x06, 0x83, 0x19, 0xf9, 0x16, 0x96, 0x16, 0x63, 0x94, 0xc3, 0x74, 0x9f, - 0xec, 0xe3, 0x2f, 0x83, 0xd5, 0x33, 0xe9, 0x60, 0xbd, 0x7a, 0xe7, 0x77, 0xb0, 0x6a, 0xe5, 0xf8, - 0x92, 0x6b, 0xf8, 0x46, 0xe4, 0x06, 0xf1, 0x1f, 0x7f, 0xb9, 0x9e, 0x6c, 0x8e, 0xbb, 0x87, 0xf3, - 0x88, 0xf4, 0x85, 0xd4, 0x26, 0x42, 0x69, 0xe7, 0xd8, 0x8a, 0x65, 0x5a, 0x19, 0x8d, 0x2e, 0x1d, - 0xa7, 0xf7, 0x8c, 0x3f, 0xc0, 0xa6, 0xd3, 0xbd, 0x26, 0x54, 0x49, 0x7b, 0x27, 0xcd, 0x3c, 0x5e, - 0xb1, 0x43, 0x05, 0x57, 0xda, 0x8b, 0x81, 0x82, 0x12, 0xf8, 0x23, 0x6d, 0x30, 0x18, 0x45, 0x59, - 0xea, 0xdb, 0x93, 0xe9, 0x0f, 0x17, 0xe5, 0x9d, 0xd7, 0xac, 0xeb, 0xbc, 0x5c, 0xcd, 0xba, 0xd3, - 0x32, 0xe1, 0xd3, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x17, 0xbc, 0x43, 0x51, 0x01, 0x00, - 0x00, + Metadata: "stream.proto", +} + +func init() { proto.RegisterFile("stream.proto", fileDescriptor_stream_b89e769b981cf265) } + +var fileDescriptor_stream_b89e769b981cf265 = []byte{ + // 173 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2e, 0x29, 0x4a, + 0x4d, 0xcc, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0xd8, + 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, + 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x45, 0x2e, 0xd6, 0xa0, 0xd4, 0x82, 0x9c, + 0x4a, 0x21, 0x09, 0x2e, 0xf6, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0x74, 0x98, 0x3c, 0x8c, 0x6b, 0xb4, + 0x98, 0x91, 0x8b, 0xc3, 0xbd, 0x28, 0xb3, 0x20, 0x37, 0x3f, 0x39, 0x5b, 0xc8, 0x80, 0x8b, 0xa7, + 0x38, 0xb5, 0xa8, 0x2c, 0xb5, 0x28, 0x18, 0x6c, 0xbc, 0x10, 0xbf, 0x1e, 0xd4, 0x56, 0xa8, 0x25, + 0x52, 0xbc, 0x08, 0x81, 0x82, 0x9c, 0x4a, 0x03, 0x46, 0x90, 0x8e, 0xe4, 0x9c, 0xcc, 0xd4, 0xbc, + 0x12, 0xe2, 0x74, 0x68, 0x30, 0x0a, 0x19, 0x73, 0xf1, 0x26, 0x65, 0xa6, 0x64, 0x16, 0xa5, 0x26, + 0x97, 0x64, 0xe6, 0xe7, 0x25, 0xe6, 0x10, 0xd6, 0x62, 0xc0, 0x98, 0xc4, 0x06, 0xf6, 0xb6, 0x31, + 0x20, 0x00, 0x00, 0xff, 0xff, 0x62, 0x90, 0x1d, 0x75, 0x06, 0x01, 0x00, 0x00, } diff --git a/example/pb/hello.proto b/example/stream/stream.proto similarity index 65% rename from example/pb/hello.proto rename to example/stream/stream.proto index 275ba6a4..de112f1b 100644 --- a/example/pb/hello.proto +++ b/example/stream/stream.proto @@ -1,22 +1,15 @@ syntax = "proto3"; -package main; - -import "google/protobuf/empty.proto"; -import "google/protobuf/wrappers.proto"; +package stream; // The greeting service definition. service Gripmock { - // standard grpc method - rpc SayHello (Request) returns (Reply); // server to client sreaming rpc serverStream (Request) returns (stream Reply); // client to server streaming rpc clientStream (stream Request) returns (Reply); // bidirectional streaming rpc bidirectional (stream Request) returns (stream Reply); - // using well-known-type - rpc HealthCheck(google.protobuf.Empty) returns (google.protobuf.StringValue); } // The request message containing the user's name. diff --git a/example/stubs/bidirectional-stream.json b/example/stream/stub/bidirectional-stream.json similarity index 100% rename from example/stubs/bidirectional-stream.json rename to example/stream/stub/bidirectional-stream.json diff --git a/example/stubs/client2server-stream.json b/example/stream/stub/client2server-stream.json similarity index 100% rename from example/stubs/client2server-stream.json rename to example/stream/stub/client2server-stream.json diff --git a/example/stubs/server2client-stream.json b/example/stream/stub/server2client-stream.json similarity index 100% rename from example/stubs/server2client-stream.json rename to example/stream/stub/server2client-stream.json diff --git a/example/stubs/standard.json b/example/stubs/standard.json deleted file mode 100644 index 866abb8e..00000000 --- a/example/stubs/standard.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "service":"Gripmock", - "method":"SayHello", - "input":{ - "equals":{ - "name":"tokopedia" - } - }, - "output":{ - "data":{ - "message":"Hello Tokopedia" - } - } -} \ No newline at end of file diff --git a/example/well-known-types/client/main.go b/example/well-known-types/client/main.go new file mode 100644 index 00000000..220088aa --- /dev/null +++ b/example/well-known-types/client/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "context" + "log" + "time" + + "github.com/golang/protobuf/ptypes/empty" + "google.golang.org/grpc" +) + +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) + + r, err := c.HealthCheck(context.Background(), &empty.Empty{}) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + code := r.GetFields()["code"].GetNumberValue() + log.Println("response code: %v", code) +} diff --git a/example/stubs/healthcheck.json b/example/well-known-types/stub/wkt.json similarity index 86% rename from example/stubs/healthcheck.json rename to example/well-known-types/stub/wkt.json index 868278bd..ae1ee9bb 100644 --- a/example/stubs/healthcheck.json +++ b/example/well-known-types/stub/wkt.json @@ -6,7 +6,7 @@ }, "output":{ "data":{ - "value": "OK" + "code": 200 } } } \ No newline at end of file diff --git a/example/well-known-types/well-known-types.pb.go b/example/well-known-types/well-known-types.pb.go new file mode 100644 index 00000000..dbc8d6ad --- /dev/null +++ b/example/well-known-types/well-known-types.pb.go @@ -0,0 +1,115 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: well-known-types.proto + +package main + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import empty "github.com/golang/protobuf/ptypes/empty" +import _struct "github.com/golang/protobuf/ptypes/struct" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// GripmockClient is the client API for Gripmock service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type GripmockClient interface { + HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*_struct.Struct, error) +} + +type gripmockClient struct { + cc *grpc.ClientConn +} + +func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { + return &gripmockClient{cc} +} + +func (c *gripmockClient) HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*_struct.Struct, error) { + out := new(_struct.Struct) + err := c.cc.Invoke(ctx, "/main.Gripmock/HealthCheck", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// GripmockServer is the server API for Gripmock service. +type GripmockServer interface { + HealthCheck(context.Context, *empty.Empty) (*_struct.Struct, error) +} + +func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { + s.RegisterService(&_Gripmock_serviceDesc, srv) +} + +func _Gripmock_HealthCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(empty.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GripmockServer).HealthCheck(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/main.Gripmock/HealthCheck", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GripmockServer).HealthCheck(ctx, req.(*empty.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +var _Gripmock_serviceDesc = grpc.ServiceDesc{ + ServiceName: "main.Gripmock", + HandlerType: (*GripmockServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "HealthCheck", + Handler: _Gripmock_HealthCheck_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "well-known-types.proto", +} + +func init() { + proto.RegisterFile("well-known-types.proto", fileDescriptor_well_known_types_263ba476363344a2) +} + +var fileDescriptor_well_known_types_263ba476363344a2 = []byte{ + // 139 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x4f, 0xcd, 0xc9, + 0xd1, 0xcd, 0xce, 0xcb, 0x2f, 0xcf, 0xd3, 0x2d, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0x92, 0x4e, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, + 0xd5, 0x07, 0x8b, 0x25, 0x95, 0xa6, 0xe9, 0xa7, 0xe6, 0x16, 0x94, 0x54, 0x42, 0x94, 0x48, 0xc9, + 0xa0, 0x4b, 0x16, 0x97, 0x14, 0x95, 0x26, 0x97, 0x40, 0x64, 0x8d, 0xbc, 0xb8, 0x38, 0xdc, 0x8b, + 0x32, 0x0b, 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xec, 0xb8, 0xb8, 0x3d, 0x52, 0x13, 0x73, 0x4a, 0x32, + 0x9c, 0x33, 0x52, 0x93, 0xb3, 0x85, 0xc4, 0xf4, 0x20, 0x3a, 0xf5, 0x60, 0x3a, 0xf5, 0x5c, 0x41, + 0xc6, 0x4a, 0x89, 0x63, 0x88, 0x07, 0x83, 0x4d, 0x4c, 0x62, 0x03, 0x0b, 0x18, 0x03, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xb5, 0x0e, 0x31, 0x36, 0xad, 0x00, 0x00, 0x00, +} diff --git a/example/well-known-types/well-known-types.proto b/example/well-known-types/well-known-types.proto new file mode 100644 index 00000000..6bff1157 --- /dev/null +++ b/example/well-known-types/well-known-types.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package main; + +import "google/protobuf/empty.proto"; +import "google/protobuf/struct.proto"; + +// The greeting service definition. +service Gripmock { + rpc HealthCheck(google.protobuf.Empty) returns (google.protobuf.Struct); +} From 16d806c68d968ce079f77f731c0208da1ca75e71 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Fri, 13 Sep 2019 15:26:18 +0700 Subject: [PATCH 12/17] support go package with semicolon --- protoc-gen-gripmock/generator.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 01c70c34..40dd1bb0 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -169,7 +169,15 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st continue } - alias := getAlias(proto.GetName()) + // support go_package alias declaration + // https://github.com/golang/protobuf/issues/139 + var alias string + if splits := strings.Split(pkg, ";"); len(splits) > 1 { + alias = splits[1] + } else { + alias = getAlias(proto.GetName()) + } + // in case of found same alias if ok := aliases[alias]; ok { alias = fmt.Sprintf("%s%d", alias, aliasNum) From 9a23fd38169e1b0ca67853d88d2845d8a2ab70d0 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 16:49:11 +0700 Subject: [PATCH 13/17] fix alias package --- protoc-gen-gripmock/generator.go | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 40dd1bb0..8e1a2cbf 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -141,12 +141,12 @@ func generateServer(protos []*descriptor.FileDescriptorProto, opt *Options) erro } byt := buf.Bytes() - byt, err = imports.Process("", byt, nil) + bytProcessed, err := imports.Process("", byt, nil) if err != nil { - return fmt.Errorf("formatting %v", err) + return fmt.Errorf("formatting: %v \n%s", err, string(byt)) } - _, err = opt.writer.Write(byt) + _, err = opt.writer.Write(bytProcessed) return err } @@ -162,6 +162,7 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st for _, dep := range depsFile { for _, proto := range protos { pkg := proto.GetOptions().GetGoPackage() + alias, pkg := getGoPackage(proto) // skip whether its not intended deps // or has empty Go package @@ -169,15 +170,6 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st continue } - // support go_package alias declaration - // https://github.com/golang/protobuf/issues/139 - var alias string - if splits := strings.Split(pkg, ";"); len(splits) > 1 { - alias = splits[1] - } else { - alias = getAlias(proto.GetName()) - } - // in case of found same alias if ok := aliases[alias]; ok { alias = fmt.Sprintf("%s%d", alias, aliasNum) @@ -192,10 +184,23 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st return deps } -func getAlias(protoName string) string { - splitSlash := strings.Split(protoName, "/") - split := strings.Split(splitSlash[len(splitSlash)-1], ".") - return split[0] +func getGoPackage(proto *descriptor.FileDescriptorProto) (alias string, goPackage string) { + goPackage = proto.GetOptions().GetGoPackage() + if goPackage == "" { + return + } + + // support go_package alias declaration + // https://github.com/golang/protobuf/issues/139 + if splits := strings.Split(goPackage, ";"); len(splits) > 1 { + goPackage = splits[0] + alias = splits[1] + } else { + splitSlash := strings.Split(proto.GetName(), "/") + split := strings.Split(splitSlash[len(splitSlash)-1], ".") + alias = split[0] + } + return } // change the structure also translate method type @@ -242,7 +247,7 @@ func getMessageType(protos []*descriptor.FileDescriptorProto, deps []string, tip for _, msg := range proto.GetMessageType() { if msg.GetName() == targetType { - alias := getAlias(proto.GetName()) + alias, _ := getGoPackage(proto) return fmt.Sprintf("%s.%s", alias, msg.GetName()) } } From f074c73c0088eadbef3116b039a12861ee3904f7 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 17:35:33 +0700 Subject: [PATCH 14/17] wkt example --- .github/workflows/integration-test.yml | 5 ++ .../well-known-types/well-known-types.proto | 11 ---- .../client/main.go | 11 +++- .../stub/wkt.json | 5 +- .../well_known_types.pb.go} | 56 +++++++++---------- .../well_known_types/well_known_types.proto | 10 ++++ 6 files changed, 54 insertions(+), 44 deletions(-) delete mode 100644 example/well-known-types/well-known-types.proto rename example/{well-known-types => well_known_types}/client/main.go (67%) rename example/{well-known-types => well_known_types}/stub/wkt.json (57%) rename example/{well-known-types/well-known-types.pb.go => well_known_types/well_known_types.pb.go} (52%) create mode 100644 example/well_known_types/well_known_types.proto diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 7984c512..3dce97f4 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -18,4 +18,9 @@ jobs: with: entrypoint: .github/workflows/run-example.sh args: stream + - name: Run WKT Example + uses: ./ + with: + entrypoint: .github/workflows/run-example.sh + args: well_known_types diff --git a/example/well-known-types/well-known-types.proto b/example/well-known-types/well-known-types.proto deleted file mode 100644 index 6bff1157..00000000 --- a/example/well-known-types/well-known-types.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -package main; - -import "google/protobuf/empty.proto"; -import "google/protobuf/struct.proto"; - -// The greeting service definition. -service Gripmock { - rpc HealthCheck(google.protobuf.Empty) returns (google.protobuf.Struct); -} diff --git a/example/well-known-types/client/main.go b/example/well_known_types/client/main.go similarity index 67% rename from example/well-known-types/client/main.go rename to example/well_known_types/client/main.go index 220088aa..f26fec55 100644 --- a/example/well-known-types/client/main.go +++ b/example/well_known_types/client/main.go @@ -6,6 +6,7 @@ import ( "time" "github.com/golang/protobuf/ptypes/empty" + pb "github.com/tokopedia/gripmock/example/well_known_types" "google.golang.org/grpc" ) @@ -22,10 +23,14 @@ func main() { c := pb.NewGripmockClient(conn) - r, err := c.HealthCheck(context.Background(), &empty.Empty{}) + r, err := c.ApiInfo(context.Background(), &empty.Empty{}) if err != nil { log.Fatalf("error from grpc: %v", err) } - code := r.GetFields()["code"].GetNumberValue() - log.Println("response code: %v", code) + + if r.Name != "Gripmock" { + log.Fatalf("expecting api name: Gripmock, but got '%v' instead", r.Name) + } + + log.Printf("Api Name: %v", r.Name) } diff --git a/example/well-known-types/stub/wkt.json b/example/well_known_types/stub/wkt.json similarity index 57% rename from example/well-known-types/stub/wkt.json rename to example/well_known_types/stub/wkt.json index ae1ee9bb..b87167d5 100644 --- a/example/well-known-types/stub/wkt.json +++ b/example/well_known_types/stub/wkt.json @@ -1,12 +1,13 @@ { "service":"Gripmock", - "method":"HealthCheck", + "method":"ApiInfo", "input":{ "equals":{} }, "output":{ "data":{ - "code": 200 + "name": "Gripmock", + "version": "1.0" } } } \ No newline at end of file diff --git a/example/well-known-types/well-known-types.pb.go b/example/well_known_types/well_known_types.pb.go similarity index 52% rename from example/well-known-types/well-known-types.pb.go rename to example/well_known_types/well_known_types.pb.go index dbc8d6ad..215acf97 100644 --- a/example/well-known-types/well-known-types.pb.go +++ b/example/well_known_types/well_known_types.pb.go @@ -1,13 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: well-known-types.proto +// source: well_known_types/well_known_types.proto -package main +package well_known_types import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" import empty "github.com/golang/protobuf/ptypes/empty" -import _struct "github.com/golang/protobuf/ptypes/struct" +import api "google.golang.org/genproto/protobuf/api" import ( context "golang.org/x/net/context" @@ -37,7 +37,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type GripmockClient interface { - HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*_struct.Struct, error) + ApiInfo(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*api.Api, error) } type gripmockClient struct { @@ -48,9 +48,9 @@ func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { return &gripmockClient{cc} } -func (c *gripmockClient) HealthCheck(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*_struct.Struct, error) { - out := new(_struct.Struct) - err := c.cc.Invoke(ctx, "/main.Gripmock/HealthCheck", in, out, opts...) +func (c *gripmockClient) ApiInfo(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*api.Api, error) { + out := new(api.Api) + err := c.cc.Invoke(ctx, "/well_known_types.Gripmock/ApiInfo", in, out, opts...) if err != nil { return nil, err } @@ -59,57 +59,57 @@ func (c *gripmockClient) HealthCheck(ctx context.Context, in *empty.Empty, opts // GripmockServer is the server API for Gripmock service. type GripmockServer interface { - HealthCheck(context.Context, *empty.Empty) (*_struct.Struct, error) + ApiInfo(context.Context, *empty.Empty) (*api.Api, error) } func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { s.RegisterService(&_Gripmock_serviceDesc, srv) } -func _Gripmock_HealthCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Gripmock_ApiInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(empty.Empty) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GripmockServer).HealthCheck(ctx, in) + return srv.(GripmockServer).ApiInfo(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/main.Gripmock/HealthCheck", + FullMethod: "/well_known_types.Gripmock/ApiInfo", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GripmockServer).HealthCheck(ctx, req.(*empty.Empty)) + return srv.(GripmockServer).ApiInfo(ctx, req.(*empty.Empty)) } return interceptor(ctx, in, info, handler) } var _Gripmock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "main.Gripmock", + ServiceName: "well_known_types.Gripmock", HandlerType: (*GripmockServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "HealthCheck", - Handler: _Gripmock_HealthCheck_Handler, + MethodName: "ApiInfo", + Handler: _Gripmock_ApiInfo_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "well-known-types.proto", + Metadata: "well_known_types/well_known_types.proto", } func init() { - proto.RegisterFile("well-known-types.proto", fileDescriptor_well_known_types_263ba476363344a2) + proto.RegisterFile("well_known_types/well_known_types.proto", fileDescriptor_well_known_types_79f0e9b76c3d9f98) } -var fileDescriptor_well_known_types_263ba476363344a2 = []byte{ - // 139 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x4f, 0xcd, 0xc9, - 0xd1, 0xcd, 0xce, 0xcb, 0x2f, 0xcf, 0xd3, 0x2d, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, - 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0x92, 0x4e, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, - 0xd5, 0x07, 0x8b, 0x25, 0x95, 0xa6, 0xe9, 0xa7, 0xe6, 0x16, 0x94, 0x54, 0x42, 0x94, 0x48, 0xc9, - 0xa0, 0x4b, 0x16, 0x97, 0x14, 0x95, 0x26, 0x97, 0x40, 0x64, 0x8d, 0xbc, 0xb8, 0x38, 0xdc, 0x8b, - 0x32, 0x0b, 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xec, 0xb8, 0xb8, 0x3d, 0x52, 0x13, 0x73, 0x4a, 0x32, - 0x9c, 0x33, 0x52, 0x93, 0xb3, 0x85, 0xc4, 0xf4, 0x20, 0x3a, 0xf5, 0x60, 0x3a, 0xf5, 0x5c, 0x41, - 0xc6, 0x4a, 0x89, 0x63, 0x88, 0x07, 0x83, 0x4d, 0x4c, 0x62, 0x03, 0x0b, 0x18, 0x03, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xb5, 0x0e, 0x31, 0x36, 0xad, 0x00, 0x00, 0x00, +var fileDescriptor_well_known_types_79f0e9b76c3d9f98 = []byte{ + // 133 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x4f, 0xcd, 0xc9, + 0x89, 0xcf, 0xce, 0xcb, 0x2f, 0xcf, 0x8b, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x47, 0x17, 0xd0, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x40, 0x17, 0x97, 0x92, 0x4e, 0xcf, 0xcf, 0x4f, 0xcf, + 0x49, 0xd5, 0x07, 0xcb, 0x27, 0x95, 0xa6, 0xe9, 0xa7, 0xe6, 0x16, 0x94, 0x54, 0x42, 0x94, 0x4b, + 0x49, 0xa2, 0x4b, 0x26, 0x16, 0x64, 0x42, 0xa4, 0x8c, 0x9c, 0xb9, 0x38, 0xdc, 0x8b, 0x32, 0x0b, + 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xcc, 0xb9, 0xd8, 0x1d, 0x0b, 0x32, 0x3d, 0xf3, 0xd2, 0xf2, 0x85, + 0xc4, 0xf4, 0x20, 0x5a, 0xf4, 0x60, 0x5a, 0xf4, 0x5c, 0x41, 0xe6, 0x49, 0x89, 0x60, 0x88, 0x3b, + 0x16, 0x64, 0x26, 0xb1, 0x81, 0x79, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x55, 0xb9, + 0x1e, 0xc0, 0x00, 0x00, 0x00, } diff --git a/example/well_known_types/well_known_types.proto b/example/well_known_types/well_known_types.proto new file mode 100644 index 00000000..8668cb24 --- /dev/null +++ b/example/well_known_types/well_known_types.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package well_known_types; + +import "google/protobuf/empty.proto"; +import "google/protobuf/api.proto"; + +service Gripmock { + rpc ApiInfo(google.protobuf.Empty) returns (google.protobuf.Api); +} From 1bd5c73b771dd005e8ef3883db4954b12c2466d6 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 17:46:17 +0700 Subject: [PATCH 15/17] fix example stream --- example/stream/client/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/example/stream/client/main.go b/example/stream/client/main.go index 71261cac..d94d7233 100644 --- a/example/stream/client/main.go +++ b/example/stream/client/main.go @@ -5,6 +5,7 @@ import ( "io" "log" "sync" + "time" pb "github.com/tokopedia/gripmock/example/stream" "google.golang.org/grpc" @@ -12,7 +13,11 @@ import ( func main() { // Set up a connection to the server. - conn, err := grpc.Dial("localhost:4770", grpc.WithInsecure()) + 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) } From 49d9cf07e65007e6c95721ff7096163baeaa7947 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 17:50:45 +0700 Subject: [PATCH 16/17] change event of integration test --- .github/workflows/integration-test.yml | 6 +++++- Dockerfile | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 3dce97f4..e01104ac 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -1,5 +1,9 @@ name: Integration test -on: push +on: + pull_request: + branches: + master + jobs: build: diff --git a/Dockerfile b/Dockerfile index aaeb380c..945048c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,8 +28,6 @@ RUN mv /protobuf-repo/src/ /protobuf/ RUN rm -rf /protobuf-repo -RUN apk del git - RUN mkdir -p /go/src/github.com/tokopedia/gripmock COPY . /go/src/github.com/tokopedia/gripmock From 60b329df360783061bd1ca43028b47689238e713 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 18:00:37 +0700 Subject: [PATCH 17/17] address review --- example/simple/client/main.go | 2 +- example/simple/simple.pb.go | 76 +++++++++---------- example/simple/simple.proto | 4 +- example/simple/stub/simple.json | 2 +- example/stream/stream.proto | 2 +- .../well_known_types/well_known_types.proto | 3 + protoc-gen-gripmock/generator.go | 1 - 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/example/simple/client/main.go b/example/simple/client/main.go index 2c6e8f96..990985d7 100644 --- a/example/simple/client/main.go +++ b/example/simple/client/main.go @@ -21,7 +21,7 @@ func main() { } defer conn.Close() - c := pb.NewSimpleClient(conn) + c := pb.NewGripmockClient(conn) // Contact the server and print out its response. name := "tokopedia" diff --git a/example/simple/simple.pb.go b/example/simple/simple.pb.go index e30768b9..ccb8fa77 100644 --- a/example/simple/simple.pb.go +++ b/example/simple/simple.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: simple.proto +// source: simple/simple.proto package simple @@ -35,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_simple_7ef306436b49ce3d, []int{0} + return fileDescriptor_simple_e0ad890e6f6d32ea, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -74,7 +74,7 @@ func (m *Reply) Reset() { *m = Reply{} } func (m *Reply) String() string { return proto.CompactTextString(m) } func (*Reply) ProtoMessage() {} func (*Reply) Descriptor() ([]byte, []int) { - return fileDescriptor_simple_7ef306436b49ce3d, []int{1} + return fileDescriptor_simple_e0ad890e6f6d32ea, []int{1} } func (m *Reply) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Reply.Unmarshal(m, b) @@ -114,83 +114,83 @@ var _ grpc.ClientConn // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 -// SimpleClient is the client API for Simple service. +// GripmockClient is the client API for Gripmock service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type SimpleClient interface { +type GripmockClient interface { // simple unary method SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) } -type simpleClient struct { +type gripmockClient struct { cc *grpc.ClientConn } -func NewSimpleClient(cc *grpc.ClientConn) SimpleClient { - return &simpleClient{cc} +func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { + return &gripmockClient{cc} } -func (c *simpleClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { +func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { out := new(Reply) - err := c.cc.Invoke(ctx, "/simple.Simple/SayHello", in, out, opts...) + err := c.cc.Invoke(ctx, "/simple.Gripmock/SayHello", in, out, opts...) if err != nil { return nil, err } return out, nil } -// SimpleServer is the server API for Simple service. -type SimpleServer interface { +// GripmockServer is the server API for Gripmock service. +type GripmockServer interface { // simple unary method SayHello(context.Context, *Request) (*Reply, error) } -func RegisterSimpleServer(s *grpc.Server, srv SimpleServer) { - s.RegisterService(&_Simple_serviceDesc, srv) +func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { + s.RegisterService(&_Gripmock_serviceDesc, srv) } -func _Simple_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Gripmock_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Request) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(SimpleServer).SayHello(ctx, in) + return srv.(GripmockServer).SayHello(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/simple.Simple/SayHello", + FullMethod: "/simple.Gripmock/SayHello", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(SimpleServer).SayHello(ctx, req.(*Request)) + return srv.(GripmockServer).SayHello(ctx, req.(*Request)) } return interceptor(ctx, in, info, handler) } -var _Simple_serviceDesc = grpc.ServiceDesc{ - ServiceName: "simple.Simple", - HandlerType: (*SimpleServer)(nil), +var _Gripmock_serviceDesc = grpc.ServiceDesc{ + ServiceName: "simple.Gripmock", + HandlerType: (*GripmockServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "SayHello", - Handler: _Simple_SayHello_Handler, + Handler: _Gripmock_SayHello_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "simple.proto", -} - -func init() { proto.RegisterFile("simple.proto", fileDescriptor_simple_7ef306436b49ce3d) } - -var fileDescriptor_simple_7ef306436b49ce3d = []byte{ - // 131 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0xce, 0xcc, 0x2d, - 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0xd8, - 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, - 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x45, 0x2e, 0xd6, 0xa0, 0xd4, 0x82, 0x9c, - 0x4a, 0x21, 0x09, 0x2e, 0xf6, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0x74, 0x98, 0x3c, 0x8c, 0x6b, 0x64, - 0xc2, 0xc5, 0x16, 0x0c, 0x36, 0x4b, 0x48, 0x8b, 0x8b, 0x23, 0x38, 0xb1, 0xd2, 0x23, 0x35, 0x27, - 0x27, 0x5f, 0x88, 0x5f, 0x0f, 0x6a, 0x1d, 0xd4, 0x74, 0x29, 0x5e, 0x84, 0x40, 0x41, 0x4e, 0x65, - 0x12, 0x1b, 0xd8, 0x19, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x19, 0x8a, 0x14, 0x59, 0x96, - 0x00, 0x00, 0x00, + Metadata: "simple/simple.proto", +} + +func init() { proto.RegisterFile("simple/simple.proto", fileDescriptor_simple_e0ad890e6f6d32ea) } + +var fileDescriptor_simple_e0ad890e6f6d32ea = []byte{ + // 138 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0xce, 0xcc, 0x2d, + 0xc8, 0x49, 0xd5, 0x87, 0x50, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x6c, 0x10, 0x9e, 0x92, + 0x2c, 0x17, 0x7b, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x10, 0x17, 0x4b, 0x5e, 0x62, + 0x6e, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x98, 0xad, 0xa4, 0xc8, 0xc5, 0x1a, 0x94, + 0x5a, 0x90, 0x53, 0x29, 0x24, 0xc1, 0xc5, 0x9e, 0x9b, 0x5a, 0x5c, 0x9c, 0x98, 0x0e, 0x93, 0x87, + 0x71, 0x8d, 0xcc, 0xb8, 0x38, 0xdc, 0x8b, 0x32, 0x0b, 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xb4, 0xb8, + 0x38, 0x82, 0x13, 0x2b, 0x3d, 0x52, 0x73, 0x72, 0xf2, 0x85, 0xf8, 0xf5, 0xa0, 0x16, 0x42, 0xcd, + 0x97, 0xe2, 0x45, 0x08, 0x14, 0xe4, 0x54, 0x26, 0xb1, 0x81, 0x1d, 0x62, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0x75, 0x88, 0x72, 0x2a, 0x9f, 0x00, 0x00, 0x00, } diff --git a/example/simple/simple.proto b/example/simple/simple.proto index 84c3a914..158f29e2 100644 --- a/example/simple/simple.proto +++ b/example/simple/simple.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package simple; -// The greeting service definition. -service Simple { +// The Gripmock service definition. +service Gripmock { // simple unary method rpc SayHello (Request) returns (Reply); } diff --git a/example/simple/stub/simple.json b/example/simple/stub/simple.json index 61c12fda..866abb8e 100644 --- a/example/simple/stub/simple.json +++ b/example/simple/stub/simple.json @@ -1,5 +1,5 @@ { - "service":"Simple", + "service":"Gripmock", "method":"SayHello", "input":{ "equals":{ diff --git a/example/stream/stream.proto b/example/stream/stream.proto index de112f1b..502ab571 100644 --- a/example/stream/stream.proto +++ b/example/stream/stream.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package stream; -// The greeting service definition. +// The Gripmock service definition. service Gripmock { // server to client sreaming rpc serverStream (Request) returns (stream Reply); diff --git a/example/well_known_types/well_known_types.proto b/example/well_known_types/well_known_types.proto index 8668cb24..9c5ccce0 100644 --- a/example/well_known_types/well_known_types.proto +++ b/example/well_known_types/well_known_types.proto @@ -6,5 +6,8 @@ import "google/protobuf/empty.proto"; import "google/protobuf/api.proto"; service Gripmock { + // this shows us example on using WKT as dependency + // api.proto in particular has go_package alias with semicolon + // "google.golang.org/genproto/protobuf/api;api" rpc ApiInfo(google.protobuf.Empty) returns (google.protobuf.Api); } diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 8e1a2cbf..0304886f 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -161,7 +161,6 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st aliasNum := 1 for _, dep := range depsFile { for _, proto := range protos { - pkg := proto.GetOptions().GetGoPackage() alias, pkg := getGoPackage(proto) // skip whether its not intended deps