-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-connection-factory.coffee
64 lines (56 loc) · 1.84 KB
/
test-connection-factory.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ConnectionFactory = require( '../lib/connection-factory' ).ConnectionFactory
should = require('should')
describe 'ConnectionFactory',->
it 'demands that open_connect be overridden', (done)->
factory = new ConnectionFactory()
factory.open_connection {},(err,connection)->
should.exist err
should.not.exist connection
done()
it 'demands that close_connection be overridden if connection.end and connection.close don\'t exist', (done)->
factory = new ConnectionFactory()
factory.close_connection {},(err)->
should.exist err
done()
it 'demands that execute be overridden if connection.query doesn\'t exist', (done)->
factory = new ConnectionFactory()
factory.execute {},"sql",["bindvars"],(err,result)->
should.exist err
should.not.exist result
done()
it 'uses connection.end or connection.close when available', (done)->
factory = new ConnectionFactory()
end_called = false
conn = {
end:()->end_called=true
}
factory.close_connection conn,(err)->
should.not.exist err
end_called.should.be.ok
close_called = false
conn = {
close:()->close_called=true
}
factory.close_connection conn,(err)->
should.not.exist err
close_called.should.be.ok
done()
it 'uses connection.query when available', (done)->
factory = new ConnectionFactory()
query_called = false
conn = {
query:(s,b,c)->
query_called=true
c()
}
factory.execute conn,"s",["b"],(err,result)->
should.not.exist err
query_called.should.be.ok
done()
it 'pre_process_sql is a no-op by default', (done)->
factory = new ConnectionFactory()
factory.pre_process_sql "s","b",(err,s,b)->
should.not.exist err
s.should.equal "s"
b.should.equal "b"
done()