Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Issue: BB-550
  • Loading branch information
Kerkesni committed Sep 19, 2024
1 parent 3bc7a49 commit 6ac365e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
77 changes: 77 additions & 0 deletions tests/unit/lifecycle/LifecycleBucketProcessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const {
timeOptions,
} = require('../../functional/lifecycle/configObjects');

const {
bucketProcessorEntry,
bucketProcessorV1Entry,
bucketProcessorV2Entry
} = require('../../utils/kafkaEntries');
const LifecycleTask = require('../../../extensions/lifecycle/tasks/LifecycleTask');
const LifecycleTaskV2 = require('../../../extensions/lifecycle/tasks/LifecycleTaskV2');


describe('Lifecycle Bucket Processor', () => {
let lbp;
Expand Down Expand Up @@ -197,4 +205,73 @@ describe('Lifecycle Bucket Processor', () => {
});
});
});

describe('_processBucketEntry', () => {

[
{
it: 'should use the forceLegacyListing when listing version is not ' +
'specified in the Kafka messages (default case)',
forceLegacyListing: null,
kafkaMessage: bucketProcessorEntry,
validateTask: task => task instanceof LifecycleTaskV2,
},
{
it: 'should use the forceLegacyListing when listing version is not ' +
'specified in the Kafka messages (v1 case)',
forceLegacyListing: true,
kafkaMessage: bucketProcessorEntry,
validateTask: task => task instanceof LifecycleTask && !(task instanceof LifecycleTaskV2),
},
{
it: 'should use the forceLegacyListing when listing version is not ' +
'specified in the Kafka messages (v2 case)',
forceLegacyListing: false,
kafkaMessage: bucketProcessorEntry,
validateTask: task => task instanceof LifecycleTaskV2,
},
{
it: 'should use the listing type specified in the kafka message (v1 case)',
forceLegacyListing: null,
kafkaMessage: bucketProcessorV1Entry,
validateTask: task => task instanceof LifecycleTask && !(task instanceof LifecycleTaskV2),
},
{
it: 'should use the listing type specified in the kafka message (v2 case)',
forceLegacyListing: false,
kafkaMessage: bucketProcessorV2Entry,
validateTask: task => task instanceof LifecycleTaskV2,
},
].forEach(opts => {
it(opts.it, () => {
if (opts.forceLegacyListing !== null) {
lbp._lcConfig.forceLegacyListing = opts.forceLegacyListing;
}

lbp.clientManager = {
getS3Client: () => sinon.stub(),
getBackbeatMetadataProxy: () => sinon.stub(),
};

sinon.stub(lbp, '_getBucketLifecycleConfiguration').yields(null, {
Rules: {
Status: 'Enabled',
Transitions: [{
Days: 10,
StorageClass: 'azure'
}],
ID: 'dac36d89-0005-4c78-8e00-7e9ace06a9c4'
}
});

lbp._internalTaskScheduler = [];

lbp._processBucketEntry(opts.kafkaMessage, err => {
assert.ifError(err);
assert.strictEqual(lbp._internalTaskScheduler.length, 1);
assert(opts.validateTask(lbp._internalTaskScheduler[0].task));
});
});
});
});
});
22 changes: 21 additions & 1 deletion tests/utils/kafkaEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@ const replicationEntry = {
value: '{"type":"put","bucket":"queue-populator-test-bucket","key":"hosts\\u000098500086134471999999RG001 0","value":"{\\"md-model-version\\":2,\\"owner-display-name\\":\\"Bart\\",\\"owner-id\\":\\"79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be\\",\\"content-length\\":542,\\"content-type\\":\\"text/plain\\",\\"last-modified\\":\\"2017-07-13T02:44:25.519Z\\",\\"content-md5\\":\\"01064f35c238bd2b785e34508c3d27f4\\",\\"x-amz-version-id\\":\\"null\\",\\"x-amz-server-version-id\\":\\"\\",\\"x-amz-storage-class\\":\\"sf\\",\\"x-amz-server-side-encryption\\":\\"\\",\\"x-amz-server-side-encryption-aws-kms-key-id\\":\\"\\",\\"x-amz-server-side-encryption-customer-algorithm\\":\\"\\",\\"x-amz-website-redirect-location\\":\\"\\",\\"acl\\":{\\"Canned\\":\\"private\\",\\"FULL_CONTROL\\":[],\\"WRITE_ACP\\":[],\\"READ\\":[],\\"READ_ACP\\":[]},\\"key\\":\\"\\",\\"location\\":[{\\"key\\":\\"29258f299ddfd65f6108e6cd7bd2aea9fbe7e9e0\\",\\"size\\":542,\\"start\\":0,\\"dataStoreName\\":\\"file\\",\\"dataStoreETag\\":\\"1:01064f35c238bd2b785e34508c3d27f4\\"}],\\"isDeleteMarker\\":false,\\"tags\\":{},\\"replicationInfo\\":{\\"status\\":\\"PENDING\\",\\"backends\\":[{\\"site\\":\\"sf\\",\\"status\\":\\"PENDING\\",\\"dataStoreVersionId\\":\\"B2AqTml1DtEKWJwRiOTh0tgkm8AlyH7W\\"},{\\"site\\":\\"replicationaws\\",\\"status\\":\\"PENDING\\",\\"dataStoreVersionId\\":\\"ob.rop0jdndzwVioi7v.6Q9.v9.6QOGv\\"}],\\"content\\":[\\"DATA\\",\\"METADATA\\"],\\"destination\\":\\"arn:aws:s3:::dummy-dest-bucket\\",\\"storageClass\\":\\"sf\\",\\"role\\":\\"arn:aws:iam::123456789012:role/backbeat\\"},\\"x-amz-meta-s3cmd-attrs\\":\\"uid:0/gname:root/uname:root/gid:0/mode:33188/mtime:1490807629/atime:1499845478/md5:01064f35c238bd2b785e34508c3d27f4/ctime:1490807629\\",\\"versionId\\":\\"98500086134471999999RG001 0\\",\\"isNFS\\":true}"}',
};

module.exports = { replicationEntry };
const bucketProcessorEntry = {
key: null,
value: '{"action":"processObjects","contextInfo":{"reqId":"5d37f38aef4b81d3b306"},"target":{"bucket":"bucket","owner":"48ff9529e073aeb075a00f6ba571638698f39cfa2778ebf0ac098da7030b11c5","accountId":"979878005795"},"details":{}}'
};

const bucketProcessorV1Entry = {
key: null,
value: '{"action":"processObjects","contextInfo":{"reqId":"5d37f38aef4b81d3b307"},"target":{"bucket":"v1-bucket","owner":"48ff9529e073aeb075a00f6ba571638698f39cfa2778ebf0ac098da7030b11c5","accountId":"979878005795","taskVersion":"v1"},"details":{}}'
};

const bucketProcessorV2Entry = {
key: null,
value: '{"action":"processObjects","contextInfo":{"reqId":"5d37f38aef4b81d3b308"},"target":{"bucket":"v2-bucket","owner":"48ff9529e073aeb075a00f6ba571638698f39cfa2778ebf0ac098da7030b11c5","accountId":"979878005795","taskVersion":"v2"},"details":{}}'
};

module.exports = {
replicationEntry,
bucketProcessorEntry,
bucketProcessorV1Entry,
bucketProcessorV2Entry
};

0 comments on commit 6ac365e

Please sign in to comment.