You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
improve decoder tests coverage, use actual private ("#") instead of TypeScript private
This commit is contained in:
@@ -18,7 +18,7 @@ function test(name: string, config: Test) {
|
|||||||
it('single chunk', () => {
|
it('single chunk', () => {
|
||||||
const setup = setupTest(config);
|
const setup = setupTest(config);
|
||||||
setup.decoder.write(config.toWrite);
|
setup.decoder.write(config.toWrite);
|
||||||
assertCalls(config, setup);
|
assertSpiesCalls(config, setup);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('byte by byte', () => {
|
it('byte by byte', () => {
|
||||||
@@ -26,7 +26,7 @@ function test(name: string, config: Test) {
|
|||||||
for (let i = 0; i < config.toWrite.length; i++) {
|
for (let i = 0; i < config.toWrite.length; i++) {
|
||||||
setup.decoder.write(config.toWrite.subarray(i, i + 1));
|
setup.decoder.write(config.toWrite.subarray(i, i + 1));
|
||||||
}
|
}
|
||||||
assertCalls(config, setup);
|
assertSpiesCalls(config, setup);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ function setupTest(config: Test) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertCalls(config: Test, spies: ReturnType<typeof setupTest>) {
|
function assertSpiesCalls(config: Test, spies: ReturnType<typeof setupTest>) {
|
||||||
assertSpyCalls(spies.onReplySpy, config.replies);
|
assertSpyCalls(spies.onReplySpy, config.replies);
|
||||||
assertSpyCalls(spies.onErrorReplySpy, config.errorReplies);
|
assertSpyCalls(spies.onErrorReplySpy, config.errorReplies);
|
||||||
assertSpyCalls(spies.onPushSpy, config.pushReplies);
|
assertSpyCalls(spies.onPushSpy, config.pushReplies);
|
||||||
@@ -302,6 +302,40 @@ describe('RESP Decoder', () => {
|
|||||||
replies: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
|
replies: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('with all types', {
|
||||||
|
toWrite: Buffer.from([
|
||||||
|
'*13\r\n',
|
||||||
|
'_\r\n',
|
||||||
|
'#f\r\n',
|
||||||
|
':0\r\n',
|
||||||
|
'(0\r\n',
|
||||||
|
',0\r\n',
|
||||||
|
'+\r\n',
|
||||||
|
'$0\r\n\r\n',
|
||||||
|
'=4\r\ntxt:\r\n',
|
||||||
|
'-\r\n',
|
||||||
|
'!0\r\n\r\n',
|
||||||
|
'*0\r\n',
|
||||||
|
'~0\r\n',
|
||||||
|
'%0\r\n'
|
||||||
|
].join('')),
|
||||||
|
replies: [[
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
0n,
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
new SimpleError(''),
|
||||||
|
new BlobError(''),
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
Object.create(null)
|
||||||
|
]]
|
||||||
|
});
|
||||||
|
|
||||||
test('null (RESP2 backwards compatibility)', {
|
test('null (RESP2 backwards compatibility)', {
|
||||||
toWrite: Buffer.from('*-1\r\n'),
|
toWrite: Buffer.from('*-1\r\n'),
|
||||||
replies: [null]
|
replies: [null]
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user