UNPKG

863 BJavaScriptView Raw
1'use strict'
2const co = require('co')
3const expect = require('expect.js')
4
5const describe = require('mocha').describe
6const it = require('mocha').it
7
8const Pool = require('../')
9
10describe('pool ending', () => {
11 it('ends without being used', (done) => {
12 const pool = new Pool()
13 pool.end(done)
14 })
15
16 it('ends with a promise', () => {
17 return new Pool().end()
18 })
19
20 it('ends with clients', co.wrap(function * () {
21 const pool = new Pool()
22 const res = yield pool.query('SELECT $1::text as name', ['brianc'])
23 expect(res.rows[0].name).to.equal('brianc')
24 return pool.end()
25 }))
26
27 it('allows client to finish', co.wrap(function * () {
28 const pool = new Pool()
29 const query = pool.query('SELECT $1::text as name', ['brianc'])
30 yield pool.end()
31 const res = yield query
32 expect(res.rows[0].name).to.equal('brianc')
33 }))
34})