new GrpcParser( grpcMocksDir )

Description

Parser class for GRPC Protocol mocks to define handlers for:

  • Unary calls
  • Server streaming calls
  • Client streaming calls
  • Bidirectional streaming calls
Parameters
Name Type Description
grpcMocksDir string

location of mocks dir for grpc mocks

Methods


camouflageMock( call, callback )

Description
  • Get the path of the determined handler from the call
  • Find a mock file for the handler
  • If mock file exists, apply handler compilation to generate actual values from helpers
  • Execute callback with the response and delay
  • Remove delay key if present before sending the response
  • If mock file is not found, log error and send the same error to client
Parameters
Name Type Description
call any

call object recieved with every unary call

callback any

callback to be executed once server is ready to return response


camouflageMockServerStream( call, callback )

Description
  • Get the path of the determined handler from the call
  • Find a mock file for the handler
  • If mock file exists, apply handler compilation to generate actual values from helpers
  • Split the contents of file with ==== to get responses each stream
  • Run a forEach and execute call.write() with the response and delay
  • On last index of streamArray, execute call.end()
  • Remove delay key if present before sending the response
  • If mock file is not found, log error and send the same error to client
Parameters
Name Type Description
call any

call object recieved with every unary call

callback any

callback to be executed once server is ready to return response


camouflageMockClientStream( call, callback )

Description
  • Get the path of the determined handler from the call
  • Find a mock file for the handler
  • If mock file exists, apply handler compilation to generate actual values from helpers
  • No action required on recieving client's streams
  • Once client calls end, respond with the compiled contents of the mockfile and delay
  • Remove delay key if present before sending the response
  • If mock file is not found, log error and send the same error to client
Parameters
Name Type Description
call any

call object recieved with every unary call

callback any

callback to be executed once server is ready to return response


camouflageMockBidiStream( call, callback )

Description
  • Get the path of the determined handler from the call
  • Find a mock file for the handler
  • If mock file exists, apply handler compilation to generate actual values from helpers
  • Follow a ping pong model, i.e. for every client's stream, respond with a server stream.
  • On client stream, respond with filecontent.data
  • Once client calls end, respond with filecontent.end
  • Remove delay key if present before sending the response
  • If mock file is not found, log error and send the same error to client
Parameters
Name Type Description
call any

call object recieved with every unary call

callback any

callback to be executed once server is ready to return response