-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BB-477 [test] add UpdateReplicationStatus unit test
The test checks that the "originOp" field has been reset prior to putting the updated metadata.
- Loading branch information
1 parent
22c12b4
commit 610b0c9
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |