Skip to content

Commit

Permalink
Added support for DescribeStreamSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
Hulios authored and mhart committed Nov 8, 2019
1 parent d0a27d9 commit fc6ff50
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
18 changes: 18 additions & 0 deletions actions/describeStreamSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

module.exports = function describeStreamSummary(store, data, cb) {

store.getStream(data.StreamName, function(err, stream) {
if (err) return cb(err)

stream.OpenShardCount = stream.Shards.filter(function(shard) {
return shard.SequenceNumberRange.EndingSequenceNumber == null
}).length

delete stream._seqIx
delete stream._tags
delete stream.Shards
delete stream.HasMoreShards

cb(null, {StreamDescriptionSummary: stream})
})
}
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var https = require('https'),
var MAX_REQUEST_BYTES = 7 * 1024 * 1024

var validApis = ['Kinesis_20131202'],
validOperations = ['AddTagsToStream', 'CreateStream', 'DeleteStream', 'DescribeStream', 'GetRecords',
'GetShardIterator', 'ListShards', 'ListStreams', 'ListTagsForStream', 'MergeShards', 'PutRecord', 'PutRecords',
'RemoveTagsFromStream', 'SplitShard', 'IncreaseStreamRetentionPeriod', 'DecreaseStreamRetentionPeriod'],
validOperations = ['AddTagsToStream', 'CreateStream', 'DeleteStream', 'DescribeStream', 'DescribeStreamSummary',
'GetRecords', 'GetShardIterator', 'ListShards', 'ListStreams', 'ListTagsForStream', 'MergeShards', 'PutRecord',
'PutRecords', 'RemoveTagsFromStream', 'SplitShard', 'IncreaseStreamRetentionPeriod', 'DecreaseStreamRetentionPeriod'],
actions = {},
actionValidations = {}

Expand Down
87 changes: 87 additions & 0 deletions test/describeStreamSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
var helpers = require('./helpers')

var target = 'DescribeStreamSummary',
request = helpers.request,
randomName = helpers.randomName,
opts = helpers.opts.bind(null, target),
assertType = helpers.assertType.bind(null, target),
assertValidation = helpers.assertValidation.bind(null, target),
assertNotFound = helpers.assertNotFound.bind(null, target)

describe('describeStreamSummary', function() {

describe('serializations', function() {

it('should return SerializationException when StreamName is not a String', function(done) {
assertType('StreamName', 'String', done)
})

})

describe('validations', function() {

it('should return ValidationException for no StreamName', function(done) {
assertValidation({}, [
'Value null at \'streamName\' failed to satisfy constraint: ' +
'Member must not be null',
], done)
})

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: ''}, [
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+',
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length greater than or equal to 1',
], done)
})

it('should return ValidationException for long StreamName', function(done) {
var name = new Array(129 + 1).join('a')
assertValidation({StreamName: name}, [
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128',
], done)
})

it('should return ResourceNotFoundException if stream does not exist', function(done) {
var name = randomName()
assertNotFound({StreamName: name}, 'Stream ' + name + ' under account ' +
helpers.awsAccountId + ' not found.', done)
})

})

describe('functionality', function() {

it('should return stream description summary', function(done) {
request(opts({StreamName: helpers.testStream}), function(err, res) {
if (err) return done(err)
res.statusCode.should.equal(200)
var createTime = Date.now() / 1000

res.body.StreamDescriptionSummary.StreamCreationTimestamp.should.be.above(createTime - 10)
res.body.StreamDescriptionSummary.StreamCreationTimestamp.should.be.below(createTime + 10)
delete res.body.StreamDescriptionSummary.StreamCreationTimestamp

res.body.should.eql({
StreamDescriptionSummary: {
StreamStatus: 'ACTIVE',
StreamName: helpers.testStream,
StreamARN: 'arn:aws:kinesis:' + helpers.awsRegion + ':' + helpers.awsAccountId +
':stream/' + helpers.testStream,
RetentionPeriodHours: 24,
EncryptionType: 'NONE',
EnhancedMonitoring: [{ShardLevelMetrics: []}],
OpenShardCount: 3,
},
})

done()
})
})

})

})

9 changes: 9 additions & 0 deletions validations/describeStreamSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.types = {
StreamName: {
type: 'String',
notNull: true,
regex: '[a-zA-Z0-9_.-]+',
lengthGreaterThanOrEqual: 1,
lengthLessThanOrEqual: 128,
},
}

0 comments on commit fc6ff50

Please sign in to comment.