16
16
17
17
var fs = require ( 'fs' ) ;
18
18
var path = require ( 'path' ) ;
19
+ var util = require ( 'util' ) ;
20
+ var crypto = require ( 'crypto' ) ;
19
21
var async = require ( 'async' ) ;
20
22
var db = require ( '../db' ) ( ) ;
23
+ var RemoteDB = require ( '../db/RemoteDB' ) ;
24
+
25
+ var describeRemoteDB = db instanceof RemoteDB ? describe : describe . skip ;
21
26
22
27
if ( ! Buffer . prototype . equals ) {
23
28
Buffer . prototype . equals = function ( buffer ) {
@@ -37,13 +42,15 @@ if (!Buffer.prototype.equals) {
37
42
}
38
43
39
44
describe ( 'db' , function ( ) {
45
+ this . timeout ( 50000 ) ;
46
+
40
47
before ( db . init . bind ( db ) ) ;
41
48
after ( db . end . bind ( db ) ) ;
49
+
42
50
var client = db . client ;
43
51
var transaction = client . _connection . _transaction ;
44
52
45
53
describe ( 'IMAGES' , function ( ) {
46
- this . timeout ( 5000 ) ;
47
54
before ( db . createImages . bind ( db ) ) ;
48
55
after ( db . dropImages . bind ( db ) ) ;
49
56
@@ -167,6 +174,49 @@ describe('db', function () {
167
174
168
175
async . waterfall ( [ prepare , insert , validate ] , done ) ;
169
176
} ) ;
177
+ } ) ;
178
+
179
+ describeRemoteDB ( 'HASH_BLOB' , function ( ) {
180
+ var statement ;
181
+
182
+ before ( function ( done ) {
183
+ async . series ( [
184
+ db . createHashBlobProc . bind ( db ) ,
185
+ client . prepare . bind ( client , 'call HASH_BLOB (?)' ) ,
186
+ ] , function ( err , results ) {
187
+ statement = results [ 1 ] ;
188
+ done ( err ) ;
189
+ } ) ;
190
+ } ) ;
170
191
192
+ after ( db . dropHashBlobProc . bind ( db ) ) ;
193
+
194
+ // call the procedure with images of different sizes
195
+ var images = require ( '../fixtures/images' ) ;
196
+ images . forEach ( function ( image ) {
197
+ var title = util . format ( 'should call the procedure with %s (%dB) and get its hash in a result set' ,
198
+ image . NAME , image . BDATA . length ) ;
199
+ it ( title , function ( done ) {
200
+ var params = [ image . BDATA ] ;
201
+ statement . exec ( params , function ( err , outParams , rows ) {
202
+ if ( err ) {
203
+ return done ( err ) ;
204
+ }
205
+ arguments . should . have . length ( 3 ) ;
206
+ rows . should . have . length ( 1 ) ;
207
+ rows [ 0 ] . should . eql ( {
208
+ ALGO : 'MD5' ,
209
+ DIGEST : MD5 ( image . BDATA )
210
+ } ) ;
211
+ done ( ) ;
212
+ } ) ;
213
+ } ) ;
214
+ } ) ;
171
215
} ) ;
172
- } ) ;
216
+ } ) ;
217
+
218
+ function MD5 ( data ) {
219
+ var hash = crypto . createHash ( 'md5' ) ;
220
+ hash . update ( data ) ;
221
+ return hash . digest ( 'hex' ) . toUpperCase ( ) ;
222
+ }
0 commit comments