SEBA-688 implement mock gRPC server and unit test the version command
Change-Id: Ia10a8ea5b00ce5d5100f8fffbefba96f234d4b32
diff --git a/commands/common.go b/commands/common.go
index 9810300..f07e705 100644
--- a/commands/common.go
+++ b/commands/common.go
@@ -47,7 +47,19 @@
refClient := grpcreflect.NewClient(context.Background(), reflectpb.NewServerReflectionClient(conn))
defer refClient.Reset()
- descriptor := grpcurl.DescriptorSourceFromServer(context.Background(), refClient)
+ // Intended method of use is to download the protos via reflection API. Loading the
+ // protos from a file is supported for unit testing, as the mock server does not
+ // support the reflection API.
+
+ var descriptor grpcurl.DescriptorSource
+ if GlobalConfig.Protoset != "" {
+ descriptor, err = grpcurl.DescriptorSourceFromProtoSets(GlobalConfig.Protoset)
+ if err != nil {
+ return nil, nil, err
+ }
+ } else {
+ descriptor = grpcurl.DescriptorSourceFromServer(context.Background(), refClient)
+ }
return conn, descriptor, nil
}