Skip to content

Commit 582cdaf

Browse files
authored
Assorted test fixes and cleanup (#3383)
* test: Actually test split messages in split message parsing test * cleanup: Fix spelling in tests * test: Wait on asynchronous tests * cleanup: Remove unused parameter from test method `BufferList#getByteLength` If someone did want this functionality, it would be better to use addition separate from the method anyway. * cleanup: Remove unused test function `BufferList.concat`
1 parent 5755b78 commit 582cdaf

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

packages/pg-protocol/src/inbound-parser.test.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ var expectedTwoParameterMessage = {
190190
}
191191

192192
var testForMessage = function (buffer: Buffer, expectedMessage: any) {
193-
it('recieves and parses ' + expectedMessage.name, async () => {
193+
it('receives and parses ' + expectedMessage.name, async () => {
194194
const messages = await parseBuffers([buffer])
195195
const [lastMessage] = messages
196196

@@ -487,12 +487,12 @@ describe('PgPacketStream', function () {
487487
assert.equal(message.fields[4], '!')
488488
})
489489

490-
var testMessageRecievedAfterSpiltAt = async function (split: number) {
490+
var testMessageReceivedAfterSplitAt = async function (split: number) {
491491
var firstBuffer = Buffer.alloc(fullBuffer.length - split)
492492
var secondBuffer = Buffer.alloc(fullBuffer.length - firstBuffer.length)
493493
fullBuffer.copy(firstBuffer, 0, 0)
494494
fullBuffer.copy(secondBuffer, 0, firstBuffer.length)
495-
const messages = await parseBuffers([fullBuffer])
495+
const messages = await parseBuffers([firstBuffer, secondBuffer])
496496
const message = messages[0] as any
497497
assert.equal(message.fields.length, 5)
498498
assert.equal(message.fields[0], null)
@@ -503,17 +503,19 @@ describe('PgPacketStream', function () {
503503
}
504504

505505
it('parses when split in the middle', function () {
506-
testMessageRecievedAfterSpiltAt(6)
506+
return testMessageReceivedAfterSplitAt(6)
507507
})
508508

509509
it('parses when split at end', function () {
510-
testMessageRecievedAfterSpiltAt(2)
510+
return testMessageReceivedAfterSplitAt(2)
511511
})
512512

513513
it('parses when split at beginning', function () {
514-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 2)
515-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 1)
516-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 5)
514+
return Promise.all([
515+
testMessageReceivedAfterSplitAt(fullBuffer.length - 2),
516+
testMessageReceivedAfterSplitAt(fullBuffer.length - 1),
517+
testMessageReceivedAfterSplitAt(fullBuffer.length - 5),
518+
])
517519
})
518520
})
519521

@@ -540,7 +542,7 @@ describe('PgPacketStream', function () {
540542
})
541543
}
542544
// sanity check
543-
it('recieves both messages when packet is not split', async function () {
545+
it('receives both messages when packet is not split', async function () {
544546
const messages = await parseBuffers([fullBuffer])
545547
verifyMessages(messages)
546548
})
@@ -554,7 +556,7 @@ describe('PgPacketStream', function () {
554556
verifyMessages(messages)
555557
}
556558

557-
describe('recieves both messages when packet is split', function () {
559+
describe('receives both messages when packet is split', function () {
558560
it('in the middle', function () {
559561
return splitAndVerifyTwoMessages(11)
560562
})

packages/pg-protocol/src/testing/buffer-list.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export default class BufferList {
1010
return this.add(Buffer.from([val >>> 8, val >>> 0]), front)
1111
}
1212

13-
public getByteLength(initial?: number) {
13+
public getByteLength() {
1414
return this.buffers.reduce(function (previous, current) {
1515
return previous + current.length
16-
}, initial || 0)
16+
}, 0)
1717
}
1818

1919
public addInt32(val: number, first?: boolean) {
@@ -64,12 +64,4 @@ export default class BufferList {
6464
})
6565
return result
6666
}
67-
68-
public static concat(): Buffer {
69-
var total = new BufferList()
70-
for (var i = 0; i < arguments.length; i++) {
71-
total.add(arguments[i])
72-
}
73-
return total.join()
74-
}
7567
}

packages/pg/test/buffer-list.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ p.addInt16 = function (val, front) {
1414
return this.add(Buffer.from([val >>> 8, val >>> 0]), front)
1515
}
1616

17-
p.getByteLength = function (initial) {
17+
p.getByteLength = function () {
1818
return this.buffers.reduce(function (previous, current) {
1919
return previous + current.length
20-
}, initial || 0)
20+
}, 0)
2121
}
2222

2323
p.addInt32 = function (val, first) {
@@ -65,12 +65,4 @@ p.join = function (appendLength, char) {
6565
return result
6666
}
6767

68-
BufferList.concat = function () {
69-
var total = new BufferList()
70-
for (var i = 0; i < arguments.length; i++) {
71-
total.add(arguments[i])
72-
}
73-
return total.join()
74-
}
75-
7668
module.exports = BufferList

0 commit comments

Comments
 (0)