1 | 'use strict'
|
2 | const co = require('co')
|
3 | const expect = require('expect.js')
|
4 |
|
5 | const describe = require('mocha').describe
|
6 | const it = require('mocha').it
|
7 |
|
8 | const Pool = require('../')
|
9 |
|
10 | describe('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(
|
21 | 'ends with clients',
|
22 | co.wrap(function* () {
|
23 | const pool = new Pool()
|
24 | const res = yield pool.query('SELECT $1::text as name', ['brianc'])
|
25 | expect(res.rows[0].name).to.equal('brianc')
|
26 | return pool.end()
|
27 | })
|
28 | )
|
29 |
|
30 | it(
|
31 | 'allows client to finish',
|
32 | co.wrap(function* () {
|
33 | const pool = new Pool()
|
34 | const query = pool.query('SELECT $1::text as name', ['brianc'])
|
35 | yield pool.end()
|
36 | const res = yield query
|
37 | expect(res.rows[0].name).to.equal('brianc')
|
38 | })
|
39 | )
|
40 | })
|