You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
* wip * Worked on phrasing etc for v5 doc changes. * Removed quite repetition of 'Rather' * Update v4-to-v5.md * Update v4-to-v5.md * Update v4-to-v5.md * WIP * WIP * clean SET command * some more commands, multi.exec<'typed'> * "typed" multi * WIP * upgrade deps * wip * wip * fix #2469 * wip * npm update * wip * wip * wip * wip * some tests * tests.yml * wip * wip * merge master into v5 * some more commands * some more commands * WIP * Release client@2.0.0-next.1 --------- Co-authored-by: Simon Prickett <simon@redislabs.com>
196 lines
5.7 KiB
TypeScript
196 lines
5.7 KiB
TypeScript
// import { strict as assert } from 'assert';
|
|
// import { SinonSpy, spy } from 'sinon';
|
|
// import RESP2Decoder from './decoder';
|
|
// import { ErrorReply } from '../../errors';
|
|
|
|
// interface DecoderAndSpies {
|
|
// decoder: RESP2Decoder;
|
|
// returnStringsAsBuffersSpy: SinonSpy;
|
|
// onReplySpy: SinonSpy;
|
|
// }
|
|
|
|
// function createDecoderAndSpies(returnStringsAsBuffers: boolean): DecoderAndSpies {
|
|
// const returnStringsAsBuffersSpy = spy(() => returnStringsAsBuffers),
|
|
// onReplySpy = spy();
|
|
|
|
// return {
|
|
// decoder: new RESP2Decoder({
|
|
// returnStringsAsBuffers: returnStringsAsBuffersSpy,
|
|
// onReply: onReplySpy
|
|
// }),
|
|
// returnStringsAsBuffersSpy,
|
|
// onReplySpy
|
|
// };
|
|
// }
|
|
|
|
// function writeChunks(stream: RESP2Decoder, buffer: Buffer) {
|
|
// let i = 0;
|
|
// while (i < buffer.length) {
|
|
// stream.write(buffer.slice(i, ++i));
|
|
// }
|
|
// }
|
|
|
|
// type Replies = Array<Array<unknown>>;
|
|
|
|
// interface TestsOptions {
|
|
// toWrite: Buffer;
|
|
// returnStringsAsBuffers: boolean;
|
|
// replies: Replies;
|
|
// }
|
|
|
|
// function generateTests({
|
|
// toWrite,
|
|
// returnStringsAsBuffers,
|
|
// replies
|
|
// }: TestsOptions): void {
|
|
// it('single chunk', () => {
|
|
// const { decoder, returnStringsAsBuffersSpy, onReplySpy } =
|
|
// createDecoderAndSpies(returnStringsAsBuffers);
|
|
// decoder.write(toWrite);
|
|
// assert.equal(returnStringsAsBuffersSpy.callCount, replies.length);
|
|
// testReplies(onReplySpy, replies);
|
|
// });
|
|
|
|
// it('multiple chunks', () => {
|
|
// const { decoder, returnStringsAsBuffersSpy, onReplySpy } =
|
|
// createDecoderAndSpies(returnStringsAsBuffers);
|
|
// writeChunks(decoder, toWrite);
|
|
// assert.equal(returnStringsAsBuffersSpy.callCount, replies.length);
|
|
// testReplies(onReplySpy, replies);
|
|
// });
|
|
// }
|
|
|
|
// function testReplies(spy: SinonSpy, replies: Replies): void {
|
|
// if (!replies) {
|
|
// assert.equal(spy.callCount, 0);
|
|
// return;
|
|
// }
|
|
|
|
// assert.equal(spy.callCount, replies.length);
|
|
// for (const [i, reply] of replies.entries()) {
|
|
// assert.deepEqual(
|
|
// spy.getCall(i).args,
|
|
// reply
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// describe('RESP2Parser', () => {
|
|
// describe('Simple String', () => {
|
|
// describe('as strings', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('+OK\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [['OK']]
|
|
// });
|
|
// });
|
|
|
|
// describe('as buffers', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('+OK\r\n'),
|
|
// returnStringsAsBuffers: true,
|
|
// replies: [[Buffer.from('OK')]]
|
|
// });
|
|
// });
|
|
// });
|
|
|
|
// describe('Error', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('-ERR\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[new ErrorReply('ERR')]]
|
|
// });
|
|
// });
|
|
|
|
// describe('Integer', () => {
|
|
// describe('-1', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from(':-1\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[-1]]
|
|
// });
|
|
// });
|
|
|
|
// describe('0', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from(':0\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[0]]
|
|
// });
|
|
// });
|
|
// });
|
|
|
|
// describe('Bulk String', () => {
|
|
// describe('null', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('$-1\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[null]]
|
|
// });
|
|
// });
|
|
|
|
// describe('as strings', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('$2\r\naa\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [['aa']]
|
|
// });
|
|
// });
|
|
|
|
// describe('as buffers', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('$2\r\naa\r\n'),
|
|
// returnStringsAsBuffers: true,
|
|
// replies: [[Buffer.from('aa')]]
|
|
// });
|
|
// });
|
|
// });
|
|
|
|
// describe('Array', () => {
|
|
// describe('null', () => {
|
|
// generateTests({
|
|
// toWrite: Buffer.from('*-1\r\n'),
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[null]]
|
|
// });
|
|
// });
|
|
|
|
// const arrayBuffer = Buffer.from(
|
|
// '*5\r\n' +
|
|
// '+OK\r\n' +
|
|
// '-ERR\r\n' +
|
|
// ':0\r\n' +
|
|
// '$1\r\na\r\n' +
|
|
// '*0\r\n'
|
|
// );
|
|
|
|
// describe('as strings', () => {
|
|
// generateTests({
|
|
// toWrite: arrayBuffer,
|
|
// returnStringsAsBuffers: false,
|
|
// replies: [[[
|
|
// 'OK',
|
|
// new ErrorReply('ERR'),
|
|
// 0,
|
|
// 'a',
|
|
// []
|
|
// ]]]
|
|
// });
|
|
// });
|
|
|
|
// describe('as buffers', () => {
|
|
// generateTests({
|
|
// toWrite: arrayBuffer,
|
|
// returnStringsAsBuffers: true,
|
|
// replies: [[[
|
|
// Buffer.from('OK'),
|
|
// new ErrorReply('ERR'),
|
|
// 0,
|
|
// Buffer.from('a'),
|
|
// []
|
|
// ]]]
|
|
// });
|
|
// });
|
|
// });
|
|
// });
|