Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

Commit

Permalink
Validation order has become non-deterministic, use arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mhart committed Jan 5, 2016
1 parent 8b976e0 commit 0c52a1e
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 240 deletions.
24 changes: 12 additions & 12 deletions test/addTagsToStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ describe('addTagsToStream', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: '', Tags: {}},
'3 validation errors detected: ' +
assertValidation({StreamName: '', Tags: {}}, [
'Value \'{}\' at \'tags\' failed to satisfy constraint: ' +
'Member must have length greater than or equal to 1; ' +
'Member must have length greater than or equal to 1',
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'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)
'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, Tags: {'a;b': 'b'}},
'1 validation error detected: ' +
assertValidation({StreamName: name, Tags: {'a;b': 'b'}}, [
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

it('should return ValidationException for long tag key', function(done) {
Expand Down
27 changes: 14 additions & 13 deletions test/createStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,33 @@ describe('createStream', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: '', ShardCount: 0},
'3 validation errors detected: ' +
assertValidation({StreamName: '', ShardCount: 0}, [
'Value \'0\' at \'shardCount\' failed to satisfy constraint: ' +
'Member must have value greater than or equal to 1; ' +
'Member must have value greater than or equal to 1',
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'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)
'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, ShardCount: 100000000000},
'2 validation errors detected: ' +
'Value \'2147483647\' at \'shardCount\' failed to satisfy constraint: Member must have value less than or equal to 100000; ' +
assertValidation({StreamName: name, ShardCount: 100000000000}, [
'Value \'2147483647\' at \'shardCount\' failed to satisfy constraint: ' +
'Member must have value less than or equal to 100000',
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

it('should return LimitExceededException for large ShardCount', function(done) {
Expand Down
27 changes: 14 additions & 13 deletions test/decreaseStreamRetentionPeriod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,31 @@ describe('decreaseStreamRetentionPeriod', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: '', RetentionPeriodHours: -1},
'3 validation errors detected: ' +
assertValidation({StreamName: '', RetentionPeriodHours: -1}, [
'Value \'-1\' at \'retentionPeriodHours\' failed to satisfy constraint: ' +
'Member must have value greater than or equal to 1; 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)
'Member must have value greater than or equal to 1',
'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, RetentionPeriodHours: 24},
'1 validation error detected: ' +
assertValidation({StreamName: name, RetentionPeriodHours: 24}, [
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

it('should return InvalidArgumentException for retention period less than 24', function(done) {
Expand Down
20 changes: 10 additions & 10 deletions test/deleteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ describe('deleteStream', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: ''},
'2 validation errors detected: ' +
assertValidation({StreamName: ''}, [
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'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)
'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},
'1 validation error detected: ' +
assertValidation({StreamName: name}, [
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

it('should return ResourceNotFoundException if stream does not exist', function(done) {
Expand Down
30 changes: 15 additions & 15 deletions test/describeStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ describe('describeStream', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: '', Limit: 0, ExclusiveStartShardId: ''},
'5 validation errors detected: ' +
assertValidation({StreamName: '', Limit: 0, ExclusiveStartShardId: ''}, [
'Value \'0\' at \'limit\' failed to satisfy constraint: ' +
'Member must have value greater than or equal to 1; ' +
'Member must have value greater than or equal to 1',
'Value \'\' at \'exclusiveStartShardId\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+',
'Value \'\' at \'exclusiveStartShardId\' failed to satisfy constraint: ' +
'Member must have length greater than or equal to 1; ' +
'Member must have length greater than or equal to 1',
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'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)
'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, Limit: 100000, ExclusiveStartShardId: name},
'3 validation errors detected: ' +
assertValidation({StreamName: name, Limit: 100000, ExclusiveStartShardId: name}, [
'Value \'100000\' at \'limit\' failed to satisfy constraint: ' +
'Member must have value less than or equal to 10000; ' +
'Member must have value less than or equal to 10000',
'Value \'' + name + '\' at \'exclusiveStartShardId\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128; ' +
'Member must have length less than or equal to 128',
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

it('should return ResourceNotFoundException if stream does not exist', function(done) {
Expand Down
22 changes: 11 additions & 11 deletions test/getRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ describe('getRecords', function() {
describe('validations', function() {

it('should return ValidationException for no ShardIterator', function(done) {
assertValidation({},
'1 validation error detected: ' +
assertValidation({}, [
'Value null at \'shardIterator\' failed to satisfy constraint: ' +
'Member must not be null', done)
'Member must not be null',
], done)
})

it('should return ValidationException for empty ShardIterator', function(done) {
assertValidation({ShardIterator: '', Limit: 0},
'2 validation errors detected: ' +
assertValidation({ShardIterator: '', Limit: 0}, [
'Value \'0\' at \'limit\' failed to satisfy constraint: ' +
'Member must have value greater than or equal to 1; ' +
'Member must have value greater than or equal to 1',
'Value \'\' at \'shardIterator\' failed to satisfy constraint: ' +
'Member must have length greater than or equal to 1', done)
'Member must have length greater than or equal to 1',
], done)
})

it('should return ValidationException for long ShardIterator', function(done) {
var name = new Array(513 + 1).join('a')
assertValidation({ShardIterator: name, Limit: 100000},
'2 validation errors detected: ' +
assertValidation({ShardIterator: name, Limit: 100000}, [
'Value \'100000\' at \'limit\' failed to satisfy constraint: ' +
'Member must have value less than or equal to 10000; ' +
'Member must have value less than or equal to 10000',
'Value \'' + name + '\' at \'shardIterator\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 512', done)
'Member must have length less than or equal to 512',
], done)
})

it('should return InvalidArgumentException if ShardIterator is incorrect format', function(done) {
Expand Down
42 changes: 21 additions & 21 deletions test/getShardIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,51 @@ describe('getShardIterator', function() {
describe('validations', function() {

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

it('should return ValidationException for empty StreamName', function(done) {
assertValidation({StreamName: '', ShardIteratorType: '', ShardId: '', StartingSequenceNumber: ''},
'6 validation errors detected: ' +
assertValidation({StreamName: '', ShardIteratorType: '', ShardId: '', StartingSequenceNumber: ''}, [
'Value \'\' at \'shardId\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+',
'Value \'\' at \'shardId\' failed to satisfy constraint: ' +
'Member must have length greater than or equal to 1; ' +
'Member must have length greater than or equal to 1',
'Value \'\' at \'shardIteratorType\' failed to satisfy constraint: ' +
'Member must satisfy enum value set: [AFTER_SEQUENCE_NUMBER, LATEST, AT_SEQUENCE_NUMBER, TRIM_HORIZON]; ' +
'Member must satisfy enum value set: [AFTER_SEQUENCE_NUMBER, LATEST, AT_SEQUENCE_NUMBER, TRIM_HORIZON]',
'Value \'\' at \'startingSequenceNumber\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: 0|([1-9]\\d{0,128}); ' +
'Member must satisfy regular expression pattern: 0|([1-9]\\d{0,128})',
'Value \'\' at \'streamName\' failed to satisfy constraint: ' +
'Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+; ' +
'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)
'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, ShardId: name, ShardIteratorType: 'LATEST'},
'2 validation errors detected: ' +
assertValidation({StreamName: name, ShardId: name, ShardIteratorType: 'LATEST'}, [
'Value \'' + name + '\' at \'shardId\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128; ' +
'Member must have length less than or equal to 128',
'Value \'' + name + '\' at \'streamName\' failed to satisfy constraint: ' +
'Member must have length less than or equal to 128', done)
'Member must have length less than or equal to 128',
], done)
})

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

it('should return ResourceNotFoundException if unknown stream and shard ID just small enough', function(done) {
Expand Down
27 changes: 21 additions & 6 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,29 @@ function assertValidation(target, data, msg, done) {
request(opts(target, data), function(err, res) {
if (err) return done(err)
res.statusCode.should.equal(400)
if (msg instanceof RegExp) {
res.body.__type.should.equal('ValidationException')
res.body.__type.should.equal('ValidationException')
var resMsg = res.body.message
if (Array.isArray(msg)) {
var msgPrefix = msg.length + ' validation ' + (msg.length == 1 ? 'error' : 'errors') + ' detected: '
resMsg.should.startWith(msgPrefix)
resMsg = resMsg.slice(msgPrefix.length)
while (msg.length) {
for (var i = 0; i < msg.length; i++) {
if (resMsg.indexOf(msg[i]) === 0) {
resMsg = resMsg.slice(msg[i].length)
if (resMsg.indexOf('; ') === 0) resMsg = resMsg.slice(2)
break
}
}
if (i >= msg.length) {
throw new Error('Could not match ' + resMsg + ' from ' + msg)
}
msg.splice(i, 1)
}
} else if (msg instanceof RegExp) {
res.body.message.should.match(msg)
} else {
res.body.should.eql({
__type: 'ValidationException',
message: msg,
})
res.body.message.should.equal(msg)
}
done()
})
Expand Down
Loading

0 comments on commit 0c52a1e

Please sign in to comment.