Skip to content

Commit 05d19b0

Browse files
committed
test: add empty commitData test case for parsePush
1 parent 654d535 commit 05d19b0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/testParsePush.test.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
unpack
1111
} = require('../src/proxy/processors/push-action/parsePush');
1212

13-
import { FLUSH_PACKET, PACK_SIGNATURE } from '../src/proxy/processors/constants';
13+
import { EMPTY_COMMIT_HASH, FLUSH_PACKET, PACK_SIGNATURE } from '../src/proxy/processors/constants';
1414

1515
/**
1616
* Creates a simplified sample PACK buffer for testing.
@@ -64,6 +64,20 @@ function createPacketLineBuffer(lines) {
6464
return buffer;
6565
}
6666

67+
/**
68+
* Creates an empty PACK buffer for testing.
69+
* @return {Buffer} - The generated buffer containing the PACK header and checksum.
70+
*/
71+
function createEmptyPackBuffer() {
72+
const header = Buffer.alloc(12);
73+
header.write(PACK_SIGNATURE, 0, 4, 'utf-8'); // signature
74+
header.writeUInt32BE(2, 4); // version
75+
header.writeUInt32BE(0, 8); // number of entries
76+
77+
const checksum = Buffer.alloc(20); // fake checksum (all zeros)
78+
return Buffer.concat([header, checksum]);
79+
}
80+
6781
describe('parsePackFile', () => {
6882
let action;
6983
let req;
@@ -442,6 +456,28 @@ describe('parsePackFile', () => {
442456
expect(step.error).to.be.true;
443457
expect(step.errorMessage).to.include('Invalid PACK data structure');
444458
});
459+
460+
it('should return empty commitData on empty branch push', async () => {
461+
const emptyPackBuffer = createEmptyPackBuffer();
462+
463+
const newCommit = 'b'.repeat(40);
464+
const ref = 'refs/heads/feature/emptybranch';
465+
const packetLine = `${EMPTY_COMMIT_HASH} ${newCommit} ${ref}\0capabilities\n`;
466+
467+
req.body = Buffer.concat([createPacketLineBuffer([packetLine]), emptyPackBuffer]);
468+
469+
const result = await exec(req, action);
470+
471+
expect(result).to.equal(action);
472+
473+
const step = action.steps.find(s => s.stepName === 'parsePackFile');
474+
expect(step).to.exist;
475+
expect(step.error).to.be.false;
476+
expect(action.branch).to.equal(ref);
477+
expect(action.setCommit.calledOnceWith(EMPTY_COMMIT_HASH, newCommit)).to.be.true;
478+
479+
expect(action.commitData).to.be.an('array').with.lengthOf(0);
480+
});
445481
});
446482

447483
describe('getPackMeta', () => {

0 commit comments

Comments
 (0)