Skip to content

Commit 94a2c72

Browse files
committed
Add unit tests for DynamoDB generatePointerHash
1 parent 1ce911d commit 94a2c72

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

Diff for: packages/datadog-plugin-aws-sdk/test/util.spec.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,59 @@
11
const { generatePointerHash, encodeValue, extractPrimaryKeys } = require('../src/util')
22

33
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+
})
814

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+
})
1219
})
1320

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+
})
1757
})
1858
})
1959

0 commit comments

Comments
 (0)