|
| 1 | +import { strict as assert } from 'assert'; |
| 2 | +import testUtils, { GLOBAL } from '../test-utils'; |
| 3 | +import { transformArguments } from './RESTORE'; |
| 4 | + |
| 5 | +describe('RESTORE', () => { |
| 6 | + describe('transformArguments', () => { |
| 7 | + it('simple', () => { |
| 8 | + assert.deepEqual( |
| 9 | + transformArguments('key', 0, 'value'), |
| 10 | + ['RESTORE', 'key', '0', 'value'] |
| 11 | + ); |
| 12 | + }); |
| 13 | + |
| 14 | + it('with REPLACE', () => { |
| 15 | + assert.deepEqual( |
| 16 | + transformArguments('key', 0, 'value', { |
| 17 | + REPLACE: true |
| 18 | + }), |
| 19 | + ['RESTORE', 'key', '0', 'value', 'REPLACE'] |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + it('with ABSTTL', () => { |
| 24 | + assert.deepEqual( |
| 25 | + transformArguments('key', 0, 'value', { |
| 26 | + ABSTTL: true |
| 27 | + }), |
| 28 | + ['RESTORE', 'key', '0', 'value', 'ABSTTL'] |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it('with IDLETIME', () => { |
| 33 | + assert.deepEqual( |
| 34 | + transformArguments('key', 0, 'value', { |
| 35 | + IDLETIME: 1 |
| 36 | + }), |
| 37 | + ['RESTORE', 'key', '0', 'value', 'IDLETIME', '1'] |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it('with FREQ', () => { |
| 42 | + assert.deepEqual( |
| 43 | + transformArguments('key', 0, 'value', { |
| 44 | + FREQ: 1 |
| 45 | + }), |
| 46 | + ['RESTORE', 'key', '0', 'value', 'FREQ', '1'] |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it('with REPLACE, ABSTTL, IDLETIME and FREQ', () => { |
| 51 | + assert.deepEqual( |
| 52 | + transformArguments('key', 0, 'value', { |
| 53 | + REPLACE: true, |
| 54 | + ABSTTL: true, |
| 55 | + IDLETIME: 1, |
| 56 | + FREQ: 2 |
| 57 | + }), |
| 58 | + ['RESTORE', 'key', '0', 'value', 'REPLACE', 'ABSTTL', 'IDLETIME', '1', 'FREQ', '2'] |
| 59 | + ); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + testUtils.testWithClient('client.restore', async client => { |
| 64 | + const [, dump] = await Promise.all([ |
| 65 | + client.set('source', 'value'), |
| 66 | + client.dump(client.commandOptions({ returnBuffers: true }), 'source') |
| 67 | + ]); |
| 68 | + |
| 69 | + assert.equal( |
| 70 | + await client.restore('destination', 0, dump), |
| 71 | + 'OK' |
| 72 | + ); |
| 73 | + }, GLOBAL.SERVERS.OPEN); |
| 74 | +}); |
0 commit comments