Skip to content

Commit cadac06

Browse files
committed
chore: normalize commit content throughout tests
1 parent a33101d commit cadac06

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

test/testParsePush.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
exec,
77
getCommitData,
88
getPackMeta,
9+
parsePacketLines,
910
unpack
1011
} = require('../src/proxy/processors/push-action/parsePush');
1112

@@ -16,15 +17,18 @@ const {
1617
* @param {number} type - Type of the object (1 for commit).
1718
* @return {Buffer} - The generated PACK buffer.
1819
*/
19-
function createSamplePackBuffer(numEntries = 1, commitContent = 'tree 123\nparent 456\nauthor A <a@a> 123 +0000\ncommitter C <c@c> 456 +0000\n\nmessage', type = 1) {
20+
function createSamplePackBuffer(
21+
numEntries = 1,
22+
commitContent = 'tree 123\nparent 456\nauthor A <a@a> 123 +0000\ncommitter C <c@c> 456 +0000\n\nmessage',
23+
type = 1,
24+
) {
2025
const header = Buffer.alloc(12);
2126
header.write('PACK', 0, 4, 'utf-8'); // Signature
2227
header.writeUInt32BE(2, 4); // Version
2328
header.writeUInt32BE(numEntries, 8); // Number of entries
2429

2530
const originalContent = Buffer.from(commitContent, 'utf8');
26-
// Actual zlib used for setup
27-
const compressedContent = zlib.deflateSync(originalContent);
31+
const compressedContent = zlib.deflateSync(originalContent); // actual zlib for setup
2832

2933
// Basic type/size encoding (assumes small sizes for simplicity)
3034
// Real PACK files use variable-length encoding for size
@@ -34,10 +38,8 @@ function createSamplePackBuffer(numEntries = 1, commitContent = 'tree 123\nparen
3438
}
3539
const objectHeader = Buffer.from([typeAndSize]); // Placeholder, actual size encoding is complex
3640

37-
// Combine parts
41+
// Combine parts and append checksum
3842
const packContent = Buffer.concat([objectHeader, compressedContent]);
39-
40-
// Append checksum (dummy 20 bytes)
4143
const checksum = Buffer.alloc(20);
4244

4345
return Buffer.concat([header, packContent, checksum]);
@@ -164,7 +166,7 @@ describe('parsePackFile', () => {
164166
const step = action.steps[0];
165167
expect(step.stepName).to.equal('parsePackFile');
166168
expect(step.error).to.be.true;
167-
expect(step.errorMessage).to.include('Unable to parse push');
169+
expect(step.errorMessage).to.include('PACK data is missing');
168170

169171
expect(action.branch).to.equal(ref);
170172
expect(action.setCommit.calledOnceWith(oldCommit, newCommit)).to.be.true;
@@ -178,8 +180,8 @@ describe('parsePackFile', () => {
178180

179181
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
180182
parent abcdef1234567890abcdef1234567890abcdef12
181-
author Test Author <test@example.com> 1678886400 +0000
182-
committer Test Committer <[email protected]> 1678886460 +0100
183+
author Test Author <author@example.com> 1234567890 +0000
184+
committer Test Committer <[email protected]> 1234567890 +0000
183185
184186
feat: Add new feature
185187
@@ -217,9 +219,9 @@ describe('parsePackFile', () => {
217219
expect(parsedCommit.parent).to.equal('abcdef1234567890abcdef1234567890abcdef12');
218220
expect(parsedCommit.author).to.equal('Test Author');
219221
expect(parsedCommit.committer).to.equal('Test Committer');
220-
expect(parsedCommit.commitTimestamp).to.equal('1678886460');
222+
expect(parsedCommit.commitTimestamp).to.equal('1234567890');
221223
expect(parsedCommit.message).to.equal('feat: Add new feature\n\nThis is the commit body.');
222-
expect(parsedCommit.authorEmail).to.equal('test@example.com');
224+
expect(parsedCommit.authorEmail).to.equal('author@example.com');
223225

224226
expect(step.content.meta).to.deep.equal({
225227
sig: 'PACK',
@@ -236,8 +238,8 @@ describe('parsePackFile', () => {
236238

237239
// Commit content without a parent line
238240
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
239-
author Test Author <[email protected]> 1678886400 +0000
240-
committer Test Committer <[email protected]> 1678886460 +0100
241+
author Test Author <[email protected]> 1234567890 +0000
242+
committer Test Committer <[email protected]> 1234567890 +0100
241243
242244
feat: Initial commit`;
243245
const parentFromCommit = '0'.repeat(40); // Expected parent hash
@@ -278,8 +280,8 @@ describe('parsePackFile', () => {
278280
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
279281
parent ${parent1}
280282
parent ${parent2}
281-
author Test Author <[email protected]> 1678886400 +0000
282-
committer Test Committer <[email protected]> 1678886460 +0100
283+
author Test Author <[email protected]> 1234567890 +0000
284+
committer Test Committer <[email protected]> 1234567890 +0100
283285
284286
Merge branch 'feature'`;
285287

@@ -314,7 +316,7 @@ describe('parsePackFile', () => {
314316

315317
// Malformed commit content - missing tree line
316318
const commitContent = `parent abcdef1234567890abcdef1234567890abcdef12
317-
author Test Author <test@example.com> 1678886400 +0000
319+
author Test Author <author@example.com> 1678886400 +0000
318320
committer Test Committer <[email protected]> 1678886460 +0100
319321
320322
feat: Missing tree`;

0 commit comments

Comments
 (0)