大家好,我正在使用 nestjs 框架创建一个 grpc 微服务。谁能给我一些关于如何测试我的 grpc 微服务(单元和 e2e)的建议。
问问题
2021 次
2 回答
2
于 2020-06-29T02:42:56.387 回答
-2
这可能并不理想,但我的设置类似于使用 Jest。希望它能让你开始。
beforeAll((done) => {
client = new service.SomeService(
'localhost:55051',
grpc.credentials.createInsecure()
);
done();
});
afterAll(done => {
client = null;
done();
});
/**
* Handles gRPC responses. Takes a parser to use against the response object
* @param {function} responseParser the parser for the response object
* @returns {function} the callback to pass in to gRPC responses
*/
const responseHandler = (onErr, responseParser, done) => (err, response) => {
if (err) {
return onErr(err, done)
} else {
return responseParser(response, done);
}
};
describe('Authenticate', () => {
const callback = expected => (response, done) => {
const received = {
status: response.status,
challenge: bytes(response.challenge),
};
expect(received).toEqual(expected);
done();
const errHandler = expected => (err, done) => {
expect(err).toBe('Offline')
};
test('Gets a challenge token', (done) => {
const expected = {
status: testValues.SUCCESS,
challenge: testValues.CHALLENGE
};
client.authenticate(
{ someKey: testValues.SOME_KEY },
responseHandler(errHandler(expected), callback(expected), done)
);
});
});
于 2018-08-31T01:26:47.360 回答