Skip to content

Commit

Permalink
Update quota functional tests
Browse files Browse the repository at this point in the history
Issue: CLDSRV-606
  • Loading branch information
williamlardier committed Jan 20, 2025
1 parent 53ac45f commit 5a55fab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
14 changes: 13 additions & 1 deletion tests/functional/aws-node-sdk/test/bucket/getBucketQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const getConfig = require('../support/config');
const sendRequest = require('../quota/tooling').sendRequest;

const bucket = 'getquotatestbucket';
const quota = { quota: 1000 };
const quota = { quota: 1000n };
const largeQuota = { quota: 1000000000000n };

describe('Test get bucket quota', () => {
let s3;
Expand All @@ -31,6 +32,17 @@ describe('Test get bucket quota', () => {
}
});

it('should return the quota (large numbers)', async () => {
try {
await sendRequest('PUT', '127.0.0.1:8000', `/${bucket}/?quota=true`, JSON.stringify(largeQuota));
const data = await sendRequest('GET', '127.0.0.1:8000', `/${bucket}/?quota=true`);
assert.strictEqual(data.GetBucketQuota.Name[0], bucket);
assert.strictEqual(data.GetBucketQuota.Quota[0], '1000000000000');
} catch (err) {
assert.fail(`Expected no error, but got ${err}`);
}
});

it('should return no such bucket error', async () => {
try {
await sendRequest('GET', '127.0.0.1:8000', '/test/?quota=true');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const sendRequest = require('../quota/tooling').sendRequest;

const bucket = 'updatequotatestbucket';
const nonExistantBucket = 'updatequotatestnonexistantbucket';
const quota = { quota: 2000 };
const negativeQuota = { quota: -1000 };
const quota = { quota: 2000n };
const negativeQuota = { quota: -1000n };
const wrongquotaFromat = '1000';
const largeQuota = { quota: 1000000000000 };
const largeQuota = { quota: 1000000000000n };

describe('Test update bucket quota', () => {
let s3;
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/api/apiUtils/quotas/quotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const mockLog = {
};

const mockBucket = {
getQuota: () => 100,
getQuota: () => 100n,
getName: () => 'bucketName',
getCreationDate: () => '2022-01-01T00:00:00.000Z',
};

const mockBucketNoQuota = {
getQuota: () => 0,
getQuota: () => 0n,
getName: () => 'bucketName',
getCreationDate: () => '2022-01-01T00:00:00.000Z',
};

describe('validateQuotas (buckets)', () => {
const request = {
getQuota: () => 100,
getQuota: () => 100n,
};

beforeEach(() => {
Expand Down Expand Up @@ -336,7 +336,7 @@ describe('validateQuotas (buckets)', () => {

validateQuotas(request, {
...mockBucket,
getQuota: () => 9007199254740991,
getQuota: () => 9007199254740991n,
}, {}, ['objectPut'], 'objectPut', 1, false, mockLog, err => {
assert.strictEqual(err.is.QuotaExceeded, true);
assert.strictEqual(QuotaService._getLatestMetricsCallback.calledOnce, true);
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('validateQuotas (buckets)', () => {

describe('validateQuotas (with accounts)', () => {
const request = {
getQuota: () => 100,
getQuota: () => 100n,
};

beforeEach(() => {
Expand All @@ -400,7 +400,7 @@ describe('validateQuotas (with accounts)', () => {
it('should return null if quota is <= 0', done => {
validateQuotas(request, mockBucketNoQuota, {
account: 'test_1',
quota: 0,
quota: 0n,
}, [], '', false, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.called, false);
Expand All @@ -411,7 +411,7 @@ describe('validateQuotas (with accounts)', () => {
it('should not return null if bucket quota is <= 0 but account quota is > 0', done => {
validateQuotas(request, mockBucketNoQuota, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, [], '', false, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.called, false);
Expand All @@ -423,7 +423,7 @@ describe('validateQuotas (with accounts)', () => {
QuotaService.enabled = false;
validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, [], '', false, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.called, false);
Expand All @@ -438,7 +438,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectPut', 'getObject'], 'objectPut', 1, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.calledOnce, true);
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucketNoQuota, {
account: 'test_1',
quota: 100,
quota: 100n,
}, ['objectPut', 'getObject'], 'objectPut', 1, false, mockLog, err => {
assert.strictEqual(err.is.QuotaExceeded, true);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 1);
Expand Down Expand Up @@ -497,7 +497,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucketNoQuota, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectDelete'], 'objectDelete', -50, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 1);
Expand Down Expand Up @@ -526,7 +526,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucketNoQuota, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectDelete'], 'objectDelete', -5000, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 1);
Expand Down Expand Up @@ -555,7 +555,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectRestore', 'objectPut'], 'objectRestore', true, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 4);
Expand Down Expand Up @@ -584,7 +584,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectPut', 'getObject'], 'objectPut', 1, false, mockLog, err => {
assert.strictEqual(err.is.QuotaExceeded, true);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 2);
Expand All @@ -605,7 +605,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectRestore', 'objectPut'], 'objectRestore', true, false, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.callCount, 4);
Expand Down Expand Up @@ -634,7 +634,7 @@ describe('validateQuotas (with accounts)', () => {

validateQuotas(request, mockBucket, {
account: 'test_1',
quota: 1000,
quota: 1000n,
}, ['objectPut'], 'objectPut', true, true, mockLog, err => {
assert.ifError(err);
assert.strictEqual(QuotaService._getLatestMetricsCallback.calledTwice, true);
Expand Down

0 comments on commit 5a55fab

Please sign in to comment.