Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Test for extractPseudoKey
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Jun 13, 2019
1 parent 4a7ad20 commit 57778f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/s3Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function compareS3Key (a, b) {
}
}

function extractPseudoKey (a) {
module.exports.extractPseudoKey = function (a) {
const otherParts = a.Key.substring(47).split('/')
const timestamp = parseInt(otherParts[1])
const recordCrc = otherParts[3]
Expand Down Expand Up @@ -175,7 +175,7 @@ function listNotificationsRecursively (SQS, options, category, prefix, currentCo
let contentMessage = {
Key: key
}
var pseudoKey = extractPseudoKey(contentMessage)
var pseudoKey = module.exports.extractPseudoKey(contentMessage)
if (!alreadySeenFromS3.has(pseudoKey)) {
currentContent.push(contentMessage)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports.listObjects = function (s3, options, limitResponse) {
} else {
if (data.Contents) {
for (let content of data.Contents) {
var pseudoKey = extractPseudoKey(content)
var pseudoKey = module.exports.extractPseudoKey(content)
alreadySeenFromS3.add(pseudoKey)
}
}
Expand All @@ -249,7 +249,7 @@ module.exports.listObjects = function (s3, options, limitResponse) {
if (error) { reject(error) }
if (data) {
for (let content of data) {
var pseudoKey = extractPseudoKey(content)
var pseudoKey = module.exports.extractPseudoKey(content)
alreadySeenFromS3.add(pseudoKey)
}
}
Expand Down
12 changes: 11 additions & 1 deletion test/s3Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const radix64 = require('../lib/radix64')
const s3Helper = require('../lib/s3Helper')

test('s3Helper', (t) => {
t.plan(2)
t.plan(3)

t.test('byteArray/s3String conversion', (t) => {
t.plan(10)
Expand All @@ -16,6 +16,16 @@ test('s3Helper', (t) => {
}
})

t.test('extractPseudoKey', (t) => {
t.plan(2)
const s3Prefix = '0/xGrUe8vokl9kjAx+RTu9t6I1UnOT7mcdcizAVI+2bos=/2/1482435340000'
const data = new Uint8Array(10)
const s3Keys = s3Helper.encodeDataToS3KeyArray(s3Prefix, data)
t.equal(s3Keys.length, 1, `${t.name} encodes to one part`)
const pseudoKey = s3Helper.extractPseudoKey({ Key : s3Keys[0] })
t.equal(pseudoKey, '1482435340000-3ZYcXs', `${t.name} expected pseudo-key`)
})

t.test('encodeDataToS3KeyArray / parseS3Key', (t) => {
t.plan(3)
const s3Prefix = '0/xGrUe8vokl9kjAx+RTu9t6I1UnOT7mcdcizAVI+2bos=/2/1482435340000'
Expand Down

0 comments on commit 57778f2

Please sign in to comment.