|
1 | 1 | const { generatePointerHash, encodeValue, extractPrimaryKeys } = require('../src/util')
|
2 | 2 |
|
3 | 3 | describe('generatePointerHash', () => {
|
4 |
| - it('should generate a valid hash for a basic S3 object', () => { |
5 |
| - const hash = generatePointerHash(['some-bucket', 'some-key.data', 'ab12ef34']) |
6 |
| - expect(hash).to.equal('e721375466d4116ab551213fdea08413') |
7 |
| - }) |
| 4 | + describe('should generate a valid hash for S3 object with', () => { |
| 5 | + it('basic values', () => { |
| 6 | + const hash = generatePointerHash(['some-bucket', 'some-key.data', 'ab12ef34']) |
| 7 | + expect(hash).to.equal('e721375466d4116ab551213fdea08413') |
| 8 | + }) |
| 9 | + |
| 10 | + it('non-ascii key', () => { |
| 11 | + const hash = generatePointerHash(['some-bucket', 'some-key.你好', 'ab12ef34']) |
| 12 | + expect(hash).to.equal('d1333a04b9928ab462b5c6cadfa401f4') |
| 13 | + }) |
8 | 14 |
|
9 |
| - it('should generate a valid hash for an S3 object with a non-ascii key', () => { |
10 |
| - const hash1 = generatePointerHash(['some-bucket', 'some-key.你好', 'ab12ef34']) |
11 |
| - expect(hash1).to.equal('d1333a04b9928ab462b5c6cadfa401f4') |
| 15 | + it('multipart-upload', () => { |
| 16 | + const hash = generatePointerHash(['some-bucket', 'some-key.data', 'ab12ef34-5']) |
| 17 | + expect(hash).to.equal('2b90dffc37ebc7bc610152c3dc72af9f') |
| 18 | + }) |
12 | 19 | })
|
13 | 20 |
|
14 |
| - it('should generate a valid hash for multipart-uploaded S3 object', () => { |
15 |
| - const hash1 = generatePointerHash(['some-bucket', 'some-key.data', 'ab12ef34-5']) |
16 |
| - expect(hash1).to.equal('2b90dffc37ebc7bc610152c3dc72af9f') |
| 21 | + describe('should generate a valid hash for DynamoDB item with', () => { |
| 22 | + it('one string primary key', () => { |
| 23 | + const hash = generatePointerHash(['some-table', 'some-key', 'some-value', '', '']) |
| 24 | + expect(hash).to.equal('7f1aee721472bcb48701d45c7c7f7821') |
| 25 | + }) |
| 26 | + |
| 27 | + it('one buffered binary primary key', () => { |
| 28 | + const hash = generatePointerHash(['some-table', 'some-key', Buffer.from('some-value'), '', '']) |
| 29 | + expect(hash).to.equal('7f1aee721472bcb48701d45c7c7f7821') |
| 30 | + }) |
| 31 | + |
| 32 | + it('one number primary key', () => { |
| 33 | + const hash = generatePointerHash(['some-table', 'some-key', '123.456', '', '']) |
| 34 | + expect(hash).to.equal('434a6dba3997ce4dbbadc98d87a0cc24') |
| 35 | + }) |
| 36 | + |
| 37 | + it('one buffered number primary key', () => { |
| 38 | + const hash = generatePointerHash(['some-table', 'some-key', Buffer.from('123.456'), '', '']) |
| 39 | + expect(hash).to.equal('434a6dba3997ce4dbbadc98d87a0cc24') |
| 40 | + }) |
| 41 | + |
| 42 | + it('string and number primary key', () => { |
| 43 | + // sort primary keys lexicographically |
| 44 | + const hash = generatePointerHash(['some-table', 'other-key', '123', 'some-key', 'some-value']) |
| 45 | + expect(hash).to.equal('7aa1b80b0e49bd2078a5453399f4dd67') |
| 46 | + }) |
| 47 | + |
| 48 | + it('buffered string and number primary key', () => { |
| 49 | + const hash = generatePointerHash([ |
| 50 | + 'some-table', |
| 51 | + 'other-key', |
| 52 | + Buffer.from('123'), |
| 53 | + 'some-key', Buffer.from('some-value') |
| 54 | + ]) |
| 55 | + expect(hash).to.equal('7aa1b80b0e49bd2078a5453399f4dd67') |
| 56 | + }) |
17 | 57 | })
|
18 | 58 | })
|
19 | 59 |
|
|
0 commit comments