@@ -177,6 +177,65 @@ describe('src/schema/proto.ts', () => {
177177 'next_page_token'
178178 ) ;
179179 } ) ;
180+ it ( "should allow generate a proto has no service and its package name differ from service's" , ( ) => {
181+ const fd = new protos . google . protobuf . FileDescriptorProto ( ) ;
182+ fd . name = 'google/cloud/showcase/v1beta1/test.proto' ;
183+ fd . package = 'google.cloud.showcase.v1beta1.errors' ;
184+ const allMessages : MessagesMap = { } ;
185+ fd . messageType
186+ . filter ( message => message . name )
187+ . forEach ( message => {
188+ allMessages [ '.' + fd . package ! + '.' + message . name ! ] = message ;
189+ } ) ;
190+ const options : Options = {
191+ grpcServiceConfig : new protos . grpc . service_config . ServiceConfig ( ) ,
192+ } ;
193+ const commentsMap = new CommentsMap ( [ fd ] ) ;
194+ const proto = new Proto ( {
195+ fd,
196+ packageName : 'google.cloud.talent.v4beta1' ,
197+ allMessages,
198+ allResourceDatabase : new ResourceDatabase ( ) ,
199+ resourceDatabase : new ResourceDatabase ( ) ,
200+ options,
201+ commentsMap,
202+ } ) ;
203+ assert . deepStrictEqual ( proto . fileToGenerate , true ) ;
204+ } ) ;
205+ it ( "should not allow generate a service proto with package name differ from the param's pakage name" , ( ) => {
206+ const fd = new protos . google . protobuf . FileDescriptorProto ( ) ;
207+ fd . name = 'google/cloud/showcase/v1beta1/test.proto' ;
208+ fd . package = 'google.cloud.showcase.v1beta1.TestService' ;
209+ fd . service = [ new protos . google . protobuf . ServiceDescriptorProto ( ) ] ;
210+ fd . service [ 0 ] . name = 'service' ;
211+ fd . service [ 0 ] . method = [
212+ new protos . google . protobuf . MethodDescriptorProto ( ) ,
213+ ] ;
214+ fd . service [ 0 ] . method [ 0 ] = new protos . google . protobuf . MethodDescriptorProto ( ) ;
215+ fd . service [ 0 ] . method [ 0 ] . name = 'Test' ;
216+ fd . service [ 0 ] . method [ 0 ] . outputType =
217+ '.google.cloud.showcase.v1beta1.TestOutput' ;
218+ const options : Options = {
219+ grpcServiceConfig : new protos . grpc . service_config . ServiceConfig ( ) ,
220+ } ;
221+ const allMessages : MessagesMap = { } ;
222+ fd . messageType
223+ . filter ( message => message . name )
224+ . forEach ( message => {
225+ allMessages [ '.' + fd . package ! + '.' + message . name ! ] = message ;
226+ } ) ;
227+ const commentsMap = new CommentsMap ( [ fd ] ) ;
228+ const proto = new Proto ( {
229+ fd,
230+ packageName : 'google.cloud.showcase.v1beta1.MainService' ,
231+ allMessages,
232+ allResourceDatabase : new ResourceDatabase ( ) ,
233+ resourceDatabase : new ResourceDatabase ( ) ,
234+ options,
235+ commentsMap,
236+ } ) ;
237+ assert . deepStrictEqual ( proto . fileToGenerate , false ) ;
238+ } ) ;
180239 } ) ;
181240 describe ( 'throw error for misconfigured LRO' , ( ) => {
182241 it ( 'throw error if method returns Operation, but without operation_info option' , ( ) => {
0 commit comments