大家好我使用nestjs框架创建了一个grpc微服务。谁能给我一些关于如何测试我的grpc微服务(单位和e2e)的建议。
答案 0 :(得分:0)
答案 1 :(得分:-1)
这可能不是理想的选择,但是我使用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)
);
});
});