Skip to content

Commit 8bd8c49

Browse files
committed
(copy-from) add test with await pipeline()
1 parent b343674 commit 8bd8c49

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/copy-from.js

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const assert = require('assert')
55
const _ = require('lodash')
66
const pg = require('pg')
77
const { finished, pipeline, PassThrough } = require('stream')
8+
const { promisify } = require('util')
9+
const { spawn } = require('child_process')
810

911
const copy = require('../').from
1012

@@ -201,6 +203,23 @@ describe('copy-from', () => {
201203
})
202204
})
203205

206+
it('works with await pipeline()', async () => {
207+
if (!pipeline) return
208+
const client = new pg.Client()
209+
await client.connect()
210+
await client.query('CREATE TEMP TABLE numbers (num1 int)')
211+
try {
212+
const total = 1000
213+
const seq = spawn('seq', [1, total]).stdout
214+
const copyFromStream = client.query(copy(`COPY numbers FROM STDIN`))
215+
await promisify(pipeline)(seq, copyFromStream)
216+
const res = await client.query('SELECT count(*) FROM numbers')
217+
assert.equal(res.rows[0].count, total)
218+
} finally {
219+
await client.end()
220+
}
221+
})
222+
204223
describe('erroneous stream (syntax error)', () => {
205224
it("emits 0 'finish'", (done) => {
206225
assertCopyFromResult('syntaxError', '(field1 int)', [Buffer.from('1\n')], (err, rows, stream) => {

0 commit comments

Comments
 (0)