Permalink
Browse files

Other: Added basic services test case

  • Loading branch information...
dcodeIO committed Dec 26, 2016
1 parent b5a068f commit 93e04f1db4a9ef3accff8d071c75be3d74c0cd4a
Showing with 52 additions and 24 deletions.
  1. +0 −24 tests/_support.js
  2. +52 −0 tests/service.js

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,52 @@
var tape = require("tape");
var protobuf = require("..");
tape.test("services", function(test) {
protobuf.load("tests/data/service.proto", function(err, root) {
if (err)
return test.fail(err.message);
var myservice = root.lookup("myservice").resolveAll(),
MyService = myservice.MyService,
DoSomethingRequest = myservice.DoSomethingRequest,
DoSomethingResponse = myservice.DoSomethingResponse,
DoSomething = MyService.get("DoSomething");
function rpcImpl(method, requestData, callback) {
if (requestData) {
test.equal(method, DoSomething, "rpcImpl should reference the correct method");
test.ok(callback, "rpcImpl should provide a callback");
setTimeout(function() {
callback(null, DoSomethingResponse.create());
});
} else {
test.equal(method, null, "rpcImpl should not reference a method when closed");
test.equal(callback, null, "rpcImpl should not provide a callback when closed");
}
}
var service = MyService.create(rpcImpl);
var dataEmitted = false;
service.on("data", function(responseData) {
dataEmitted = true;
test.ok(responseData, "should emit the data event");
});
var endCalled = false;
service.on("end", function() {
test.notOk(endCalled, "should not emit the end event twice");
endCalled = true;
test.pass("should call the end event");
service.end();
test.end();
});
service.doSomething(DoSomethingRequest.create(), function(err, res) {
test.notOk(err, "should not raise an error");
test.ok(res instanceof DoSomethingResponse.getCtor(), "should return a properly typed response");
test.ok(dataEmitted, "should have emitted the data event");
service.end();
});
});
});

0 comments on commit 93e04f1

Please sign in to comment.