Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
analog-nico committed Sep 21, 2015
1 parent 13c666b commit 045641b
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/spec/local-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,58 @@ describe('Local Server', function () {

});

it('should limit all resources with a rule that defines none', function () {

var quotaManager = new quota.Manager();
quotaManager.addRule({
limit: 2,
throttling: 'limit-absolute',
resource: 'resA'
});
quotaManager.addRule({
limit: 2,
throttling: 'limit-absolute',
resource: 'resB'
});
quotaManager.addRule({
limit: 1,
throttling: 'limit-absolute'
});

var quotaServer = new quota.Server();
quotaServer.addManager('test', quotaManager);

var quotaClient = new quota.Client(quotaServer);

return BPromise.resolve()
.then(function () {
return quotaClient.requestQuota('test', undefined, { 'resA': 1 });
})
.then(function () {

return quotaClient.requestQuota('test', undefined, { 'resA': 1 })
.then(function () {
throw new Error('Expected OutOfQuotaError');
})
.catch(quota.OutOfQuotaError, function (err) {
return; // Expected
});

})
.then(function () {

return quotaClient.requestQuota('test', undefined, { 'resB': 1 })
.then(function () {
throw new Error('Expected OutOfQuotaError');
})
.catch(quota.OutOfQuotaError, function (err) {
return; // Expected
});

});

});

it('should not grant request for unknown resource', function () {

var quotaManager = new quota.Manager();
Expand All @@ -529,6 +581,30 @@ describe('Local Server', function () {

});

it('should not grant request for empty resource object', function () {

var quotaManager = new quota.Manager();
quotaManager.addRule({
limit: 1,
throttling: 'limit-absolute',
resource: 'known'
});

var quotaServer = new quota.Server();
quotaServer.addManager('test', quotaManager);

var quotaClient = new quota.Client(quotaServer);

return quotaClient.requestQuota('test', undefined, { })
.then(function () {
throw new Error('Expected OutOfQuotaError');
})
.catch(quota.OutOfQuotaError, function (err) {
return; // Expected
});

});

});

describe('with two managers', function () {
Expand Down

0 comments on commit 045641b

Please sign in to comment.