Skip to content

Commit

Permalink
test: validate attachment content
Browse files Browse the repository at this point in the history
  • Loading branch information
ricellis committed Sep 16, 2024
1 parent 7c8f46c commit 76e282d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/ci_e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

delete require.cache[require.resolve('./citestutils.js')];
const u = require('./citestutils.js');
const client = require('./hooks.js').sharedClient;
const { Writable } = require('node:stream');
const { pipeline } = require('node:stream/promises');
const assert = require('node:assert');

[{ useApi: true }, { useApi: false }].forEach(function(params) {
describe(u.scenario('End to end backup and restore', params), function() {
Expand All @@ -40,11 +44,29 @@ const u = require('./citestutils.js');
const p = u.p(params, { opts: { attachments: true } });
const expectedBackupFile = './test/fixtures/attachment.backup';
const actualBackup = `./${this.fileName}`;
const actualRestoredAttachmentChunks = [];
return u.testRestoreFromFile(p, expectedBackupFile, this.dbName)
.then(() => {
return u.testBackupToFile(p, this.dbName, actualBackup);
}).then(() => {
return u.backupFileCompare(actualBackup, expectedBackupFile);
}).then(() => {
return client.getAttachment({
db: this.dbName,
docId: 'd1',
attachmentName: 'att.txt'
});
}).then(response => {
return pipeline(
response.result, new Writable({
write(chunk, encoding, callback) {
actualRestoredAttachmentChunks.push(chunk);
callback();
}
}));
}).then(() => {
const actualRestoredAttachment = Buffer.concat(actualRestoredAttachmentChunks).toString('utf8');
assert.strictEqual(actualRestoredAttachment, 'My attachment data');
});
});
});
Expand Down

0 comments on commit 76e282d

Please sign in to comment.