Skip to content

Commit

Permalink
BB-477 [test] add UpdateReplicationStatus unit test
Browse files Browse the repository at this point in the history
The test checks that the "originOp" field has been reset prior to
putting the updated metadata.
  • Loading branch information
jonathan-gramain committed Dec 6, 2023
1 parent 22c12b4 commit 610b0c9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/unit/replication/UpdateReplicationStatus.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const assert = require('assert');
const sinon = require('sinon');

const UpdateReplicationStatus =
require('../../../extensions/replication/tasks/UpdateReplicationStatus');
const ObjectQueueEntry =
require('../../../extensions/replication/utils/ObjectQueueEntry');

const Logger = require('werelogs').Logger;
const logger = new Logger('Backbeat:Replication:UpdateReplicationStatus:tests');

describe('UpdateReplicationStatus', () => {
it('should update replication status and reset the "originOp" field', done => {
const mockRSP = {
getStateVars: sinon.stub().returns({
repConfig: {
replicationStatusProcessor: {},
},
sourceConfig: {
auth: {},
},
}),
};
const objMd = {
replicationInfo: {
status: 'PENDING',
backends: [{
site: 'sf',
status: 'PENDING',
}],
},
originOp: 's3:ObjectCreated:Put',
};
const replicationEntry = {
replicationInfo: {
status: 'COMPLETED',
backends: [{
site: 'sf',
status: 'COMPLETED',
}],
},
originOp: 's3:ObjectCreated:Put',
};
const task = new UpdateReplicationStatus(mockRSP, {
status: sinon.stub(),
});
task.backbeatSourceClient = {
getMetadata: sinon.stub().callsArgWith(2, null, { Body: JSON.stringify(objMd) }),
putMetadata: (updatedSourceEntry, log, cb) => {
assert.strictEqual(updatedSourceEntry.getReplicationStatus(), 'COMPLETED');
// originOp should have been reset before putting metadata
assert.strictEqual(updatedSourceEntry.getOriginOp(), '');
cb();
},
};
const sourceEntry = new ObjectQueueEntry('mybucket', 'mykey', replicationEntry);
sourceEntry.setSite('sf');
const log = logger.newRequestLogger();
task._updateReplicationStatus(sourceEntry, log, done);
});
});

0 comments on commit 610b0c9

Please sign in to comment.