mirror of
https://github.com/fullstorydev/grpcurl.git
synced 2026-05-23 04:01:45 +03:00
fix nil dereference (#10)
This commit is contained in:
@@ -99,7 +99,7 @@ func resolveFileDescriptor(unresolved map[string]*descriptor.FileDescriptorProto
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no descriptor found for %q", filename)
|
return nil, fmt.Errorf("no descriptor found for %q", filename)
|
||||||
}
|
}
|
||||||
deps := make([]*desc.FileDescriptor, len(fd.GetDependency()))
|
deps := make([]*desc.FileDescriptor, 0, len(fd.GetDependency()))
|
||||||
for _, dep := range fd.GetDependency() {
|
for _, dep := range fd.GetDependency() {
|
||||||
depFd, err := resolveFileDescriptor(unresolved, resolved, dep)
|
depFd, err := resolveFileDescriptor(unresolved, resolved, dep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -116,6 +116,28 @@ func TestServerDoesNotSupportReflection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProtosetWithImports(t *testing.T) {
|
||||||
|
sourceProtoset, err := DescriptorSourceFromProtoSets("testing/example.protoset")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to load protoset: %v", err)
|
||||||
|
}
|
||||||
|
// really shallow check of the loaded descriptors
|
||||||
|
if sd, err := sourceProtoset.FindSymbol("TestService"); err != nil {
|
||||||
|
t.Errorf("failed to find TestService in protoset: %v", err)
|
||||||
|
} else if sd == nil {
|
||||||
|
t.Errorf("FindSymbol returned nil for TestService")
|
||||||
|
} else if _, ok := sd.(*desc.ServiceDescriptor); !ok {
|
||||||
|
t.Errorf("FindSymbol returned wrong kind of descriptor for TestService: %T", sd)
|
||||||
|
}
|
||||||
|
if md, err := sourceProtoset.FindSymbol("TestRequest"); err != nil {
|
||||||
|
t.Errorf("failed to find TestRequest in protoset: %v", err)
|
||||||
|
} else if md == nil {
|
||||||
|
t.Errorf("FindSymbol returned nil for TestRequest")
|
||||||
|
} else if _, ok := md.(*desc.MessageDescriptor); !ok {
|
||||||
|
t.Errorf("FindSymbol returned wrong kind of descriptor for TestRequest: %T", md)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestListServicesProtoset(t *testing.T) {
|
func TestListServicesProtoset(t *testing.T) {
|
||||||
doTestListServices(t, sourceProtoset, false)
|
doTestListServices(t, sourceProtoset, false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ cd "$(dirname $0)"
|
|||||||
|
|
||||||
# Run this script to generate files used by tests.
|
# Run this script to generate files used by tests.
|
||||||
|
|
||||||
echo "Creating protoset..."
|
echo "Creating protosets..."
|
||||||
protoc ../../../google.golang.org/grpc/interop/grpc_testing/test.proto \
|
protoc ../../../google.golang.org/grpc/interop/grpc_testing/test.proto \
|
||||||
-I../../../ --include_imports \
|
-I../../../ --include_imports \
|
||||||
--descriptor_set_out=testing/test.protoset
|
--descriptor_set_out=testing/test.protoset
|
||||||
|
|
||||||
|
protoc testing/example.proto \
|
||||||
|
--include_imports \
|
||||||
|
--descriptor_set_out=testing/example.protoset
|
||||||
|
|
||||||
echo "Creating certs for TLS testing..."
|
echo "Creating certs for TLS testing..."
|
||||||
if ! hash certstrap 2>/dev/null; then
|
if ! hash certstrap 2>/dev/null; then
|
||||||
|
|||||||
19
testing/example.proto
Normal file
19
testing/example.proto
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
import "google/protobuf/descriptor.proto";
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
|
||||||
|
message TestRequest {
|
||||||
|
repeated string file_names = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TestResponse {
|
||||||
|
map<string, google.protobuf.FileDescriptorProto> file_protos = 1;
|
||||||
|
google.protobuf.Timestamp last_update_date = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
service TestService {
|
||||||
|
rpc GetFiles (TestRequest) returns (TestResponse);
|
||||||
|
rpc Ping (google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||||
|
}
|
||||||
BIN
testing/example.protoset
Normal file
BIN
testing/example.protoset
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user