Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Ignore when no kinesis stream set (useful for dev server)
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 3, 2019
1 parent 4e99497 commit ef85a31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/kinesis.js
Expand Up @@ -15,5 +15,10 @@ exports.put = async function(json) {
StreamName = StreamName.split('/').pop()
}

await kinesis.putRecord({Data, PartitionKey, StreamName}).promise()
if (StreamName) {
await kinesis.putRecord({Data, PartitionKey, StreamName}).promise()
return true
} else {
return false
}
}
8 changes: 8 additions & 0 deletions lib/kinesis.test.js
Expand Up @@ -6,6 +6,8 @@ const kinesis = require('./kinesis')

describe('kinesis', () => {

beforeEach(() => process.env.KINESIS_STREAM = 'test-stream')

it('puts data to kinesis', async () => {
await kinesis.put({foo: 'bar'})
expect(sdk.__kinesisPuts.length).toEqual(1)
Expand All @@ -30,6 +32,12 @@ describe('kinesis', () => {
expect(sdk.__kinesisPuts[0].StreamName).toEqual('anything')
})

it('ignores puts with no stream set', async () => {
process.env.KINESIS_STREAM = ''
await kinesis.put({foo: 'bar'})
expect(sdk.__kinesisPuts.length).toEqual(0)
})

it('decodes kinesis stream arns', async () => {
process.env.KINESIS_STREAM = 'arn:aws:kinesis:us-east-1:12345678:stream/anything'
await kinesis.put({foo: 'bar'})
Expand Down

0 comments on commit ef85a31

Please sign in to comment.