forked from grpc-ecosystem/grpc-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request grpc-ecosystem#312 from fische/master
Do not add imports from methods with no bindings.
- Loading branch information
Showing
8 changed files
with
214 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package abe | ||
|
||
import ( | ||
) | ||
|
||
type ProtobufDuration struct { | ||
Seconds string `json:"seconds,omitempty"` | ||
Nanos int32 `json:"nanos,omitempty"` | ||
|
||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package gengateway | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/proto" | ||
protodescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" | ||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" | ||
) | ||
|
||
func TestGenerateServiceWithoutBindings(t *testing.T) { | ||
msgdesc := &protodescriptor.DescriptorProto{ | ||
Name: proto.String("ExampleMessage"), | ||
} | ||
msg := &descriptor.Message{ | ||
DescriptorProto: msgdesc, | ||
} | ||
msg1 := &descriptor.Message{ | ||
DescriptorProto: msgdesc, | ||
File: &descriptor.File{ | ||
GoPkg: descriptor.GoPackage{ | ||
Path: "github.com/golang/protobuf/ptypes/empty", | ||
Name: "empty", | ||
}, | ||
}, | ||
} | ||
meth := &protodescriptor.MethodDescriptorProto{ | ||
Name: proto.String("Example"), | ||
InputType: proto.String("ExampleMessage"), | ||
OutputType: proto.String("ExampleMessage"), | ||
} | ||
meth1 := &protodescriptor.MethodDescriptorProto{ | ||
Name: proto.String("ExampleWithoutBindings"), | ||
InputType: proto.String("empty.Empty"), | ||
OutputType: proto.String("empty.Empty"), | ||
} | ||
svc := &protodescriptor.ServiceDescriptorProto{ | ||
Name: proto.String("ExampleService"), | ||
Method: []*protodescriptor.MethodDescriptorProto{meth, meth1}, | ||
} | ||
file := descriptor.File{ | ||
FileDescriptorProto: &protodescriptor.FileDescriptorProto{ | ||
Name: proto.String("example.proto"), | ||
Package: proto.String("example"), | ||
Dependency: []string{"a.example/b/c.proto", "a.example/d/e.proto"}, | ||
MessageType: []*protodescriptor.DescriptorProto{msgdesc}, | ||
Service: []*protodescriptor.ServiceDescriptorProto{svc}, | ||
}, | ||
GoPkg: descriptor.GoPackage{ | ||
Path: "example.com/path/to/example/example.pb", | ||
Name: "example_pb", | ||
}, | ||
Messages: []*descriptor.Message{msg}, | ||
Services: []*descriptor.Service{ | ||
{ | ||
ServiceDescriptorProto: svc, | ||
Methods: []*descriptor.Method{ | ||
{ | ||
MethodDescriptorProto: meth, | ||
RequestType: msg, | ||
ResponseType: msg, | ||
Bindings: []*descriptor.Binding{ | ||
{ | ||
HTTPMethod: "GET", | ||
Body: &descriptor.Body{FieldPath: nil}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
MethodDescriptorProto: meth1, | ||
RequestType: msg1, | ||
ResponseType: msg1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
g := &generator{} | ||
got, err := g.generate(crossLinkFixture(&file)) | ||
if err != nil { | ||
t.Errorf("generate(%#v) failed with %v; want success", file, err) | ||
return | ||
} | ||
if notwanted := `"github.com/golang/protobuf/ptypes/empty"`; strings.Contains(got, notwanted) { | ||
t.Errorf("generate(%#v) = %s; does not want to contain %s", file, got, notwanted) | ||
} | ||
} |