Skip to content

Commit

Permalink
Merge d5b9bae into 79f00a3
Browse files Browse the repository at this point in the history
  • Loading branch information
merighifacundo committed Jul 4, 2021
2 parents 79f00a3 + d5b9bae commit acb4f9d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class Mali extends Emitter {
if (typeof path === 'object' && path.root && path.file) {
protoFilePath = path.file
if (!loadOptions.includeDirs) {
loadOptions.includeDirs = [path.root]
// Support either multiple or single paths.
loadOptions.includeDirs = Array.isArray(path.root) ? path.root : [path.root]
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,66 @@ test.cb('should handle req/res request', t => {
})
})

test.cb('should handle multiple protos request', t => {
t.plan(5)
const APP_HOST = tu.getHost()
const PROTO_ROOT_FOLDER = path.resolve(__dirname, './protos')
const PROTO_ROOT_MULTIPLE = path.resolve(__dirname, './protosmultiple')
const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto')

function sayHello (ctx) {
ctx.res = { message: 'Hello ' + ctx.req.name }
}

const app = new Mali()
t.truthy(app)
app.addService({ root: [PROTO_ROOT_MULTIPLE, PROTO_ROOT_FOLDER], file: 'helloworld.proto' }, 'helloworld.Greeter')
app.use('helloworld.Greeter', 'SayHello', sayHello)
app.start(APP_HOST).then(server => {
t.truthy(server)

const pd = pl.loadSync(PROTO_PATH)
const helloproto = grpc.loadPackageDefinition(pd).helloworld
const client = new helloproto.Greeter(APP_HOST, grpc.credentials.createInsecure())
client.sayHello({ name: 'Bob' }, (err, response) => {
t.falsy(err)
t.truthy(response)
t.is(response.message, 'Hello Bob')
app.close().then(() => t.end())
})
})
})

test.cb('should handle multiple protos with second folder definitions request', t => {
t.plan(5)
const APP_HOST = tu.getHost()
const PROTO_ROOT_FOLDER = path.resolve(__dirname, './protos')
const PROTO_ROOT_MULTIPLE = path.resolve(__dirname, './protosmultiple')
const PROTO_PATH = path.resolve(__dirname, './protosmultiple/hellomultiple.proto')

function sayMultiple (ctx) {
ctx.res = { message: 'Hello Multiple ' + ctx.req.name }
}

const app = new Mali()
t.truthy(app)
app.addService({ root: [PROTO_ROOT_MULTIPLE, PROTO_ROOT_FOLDER], file: 'hellomultiple.proto' }, 'multiple.hello.GreeterMultiple')
app.use('multiple.hello.GreeterMultiple', 'SayMultiple', sayMultiple)
app.start(APP_HOST).then(server => {
t.truthy(server)

const pd = pl.loadSync(PROTO_PATH)
const helloproto = grpc.loadPackageDefinition(pd).multiple.hello
const client = new helloproto.GreeterMultiple(APP_HOST, grpc.credentials.createInsecure())
client.sayMultiple({ name: 'Bob' }, (err, response) => {
t.falsy(err)
t.truthy(response)
t.is(response.message, 'Hello Multiple Bob')
app.close().then(() => t.end())
})
})
})

test.cb('should handle req/res request where res is a promise', t => {
t.plan(5)
const APP_HOST = tu.getHost()
Expand Down
21 changes: 21 additions & 0 deletions test/protosmultiple/hellomultiple.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package multiple.hello;


// The greeting service definition.
service GreeterMultiple {
// Sends a greeting
rpc SayMultiple (HelloMultipleRequest) returns (HelloMultipleReply) {}
}

// The request message containing the user's name.
message HelloMultipleRequest {
string name = 1;
}

// The response message containing the greetings
message HelloMultipleReply {
string message = 1;
}

0 comments on commit acb4f9d

Please sign in to comment.