2
2
3
3
const Promise = require ( 'bluebird' )
4
4
5
+ const bufferise = require ( './util/bufferise' )
5
6
const crypto = require ( 'crypto' )
6
7
const path = require ( 'path' )
7
8
const Tacks = require ( 'tacks' )
@@ -13,45 +14,57 @@ const CacheContent = require('./util/cache-content')
13
14
14
15
const read = require ( '../lib/content/read' )
15
16
16
- test ( 'readStream : returns a stream with cache content data' , function ( t ) {
17
- const CONTENT = 'foobarbaz'
17
+ test ( 'read : returns a Promise with cache content data' , function ( t ) {
18
+ const CONTENT = bufferise ( 'foobarbaz' )
18
19
const DIGEST = crypto . createHash ( 'sha512' ) . update ( CONTENT ) . digest ( 'hex' )
19
20
const fixture = new Tacks ( CacheContent ( {
20
21
[ DIGEST ] : CONTENT
21
22
} ) )
22
23
fixture . create ( CACHE )
23
- const stream = read . readStream ( CACHE , DIGEST )
24
+ return read ( CACHE , DIGEST ) . then ( data => {
25
+ t . deepEqual ( data , CONTENT , 'cache contents read correctly' )
26
+ } )
27
+ } )
28
+
29
+ test ( 'read.stream: returns a stream with cache content data' , function ( t ) {
30
+ const CONTENT = bufferise ( 'foobarbaz' )
31
+ const DIGEST = crypto . createHash ( 'sha512' ) . update ( CONTENT ) . digest ( 'hex' )
32
+ const fixture = new Tacks ( CacheContent ( {
33
+ [ DIGEST ] : CONTENT
34
+ } ) )
35
+ fixture . create ( CACHE )
36
+ const stream = read . stream ( CACHE , DIGEST )
24
37
stream . on ( 'error' , function ( e ) { throw e } )
25
38
let buf = ''
26
39
stream . on ( 'data' , function ( data ) { buf += data } )
27
40
stream . on ( 'end' , function ( ) {
28
41
t . ok ( true , 'stream completed successfully' )
29
- t . equal ( CONTENT , buf , 'cache contents read correctly' )
42
+ t . deepEqual ( bufferise ( buf ) , CONTENT , 'cache contents read correctly' )
30
43
t . end ( )
31
44
} )
32
45
} )
33
46
34
- test ( 'readStream : allows hashAlgorithm configuration' , function ( t ) {
47
+ test ( 'read.stream : allows hashAlgorithm configuration' , function ( t ) {
35
48
const CONTENT = 'foobarbaz'
36
49
const HASH = 'whirlpool'
37
50
const DIGEST = crypto . createHash ( HASH ) . update ( CONTENT ) . digest ( 'hex' )
38
51
const fixture = new Tacks ( CacheContent ( {
39
52
[ DIGEST ] : CONTENT
40
53
} , HASH ) )
41
54
fixture . create ( CACHE )
42
- const stream = read . readStream ( CACHE , DIGEST , { hashAlgorithm : HASH } )
55
+ const stream = read . stream ( CACHE , DIGEST , { hashAlgorithm : HASH } )
43
56
stream . on ( 'error' , function ( e ) { throw e } )
44
57
let buf = ''
45
58
stream . on ( 'data' , function ( data ) { buf += data } )
46
59
stream . on ( 'end' , function ( ) {
47
60
t . ok ( true , 'stream completed successfully, off a sha512' )
48
- t . equal ( CONTENT , buf , 'cache contents read correctly' )
61
+ t . deepEqual ( buf , CONTENT , 'cache contents read correctly' )
49
62
t . end ( )
50
63
} )
51
64
} )
52
65
53
- test ( 'readStream : errors if content missing' , function ( t ) {
54
- const stream = read . readStream ( CACHE , 'whatnot' )
66
+ test ( 'read.stream : errors if content missing' , function ( t ) {
67
+ const stream = read . stream ( CACHE , 'whatnot' )
55
68
stream . on ( 'error' , function ( e ) {
56
69
t . ok ( e , 'got an error!' )
57
70
t . equal ( e . code , 'ENOENT' , 'error uses ENOENT error code' )
@@ -65,7 +78,7 @@ test('readStream: errors if content missing', function (t) {
65
78
} )
66
79
} )
67
80
68
- test ( 'readStream : errors if content fails checksum' , function ( t ) {
81
+ test ( 'read.stream : errors if content fails checksum' , function ( t ) {
69
82
const CONTENT = 'foobarbaz'
70
83
const DIGEST = crypto . createHash ( 'sha512' ) . update ( CONTENT ) . digest ( 'hex' )
71
84
const fixture = new Tacks ( CacheContent ( {
0 commit comments