@@ -52,14 +52,13 @@ test('read.stream: returns a stream with cache content data', function (t) {
52
52
stream . on ( 'error' , function ( e ) { throw e } )
53
53
let buf = ''
54
54
stream . on ( 'data' , function ( data ) { buf += data } )
55
- return BB . join (
55
+ return Promise . all ( [
56
56
finished ( stream ) . then ( ( ) => Buffer . from ( buf ) ) ,
57
- read ( CACHE , INTEGRITY , { size : CONTENT . length } ) ,
58
- ( fromStream , fromBulk ) => {
57
+ read ( CACHE , INTEGRITY , { size : CONTENT . length } ) ] )
58
+ . then ( ( [ fromStream , fromBulk ] ) => {
59
59
t . deepEqual ( fromStream , CONTENT , 'stream data checks out' )
60
60
t . deepEqual ( fromBulk , CONTENT , 'promise data checks out' )
61
- }
62
- )
61
+ } )
63
62
} )
64
63
65
64
test ( 'read: allows hashAlgorithm configuration' , function ( t ) {
@@ -74,14 +73,13 @@ test('read: allows hashAlgorithm configuration', function (t) {
74
73
stream . on ( 'error' , function ( e ) { throw e } )
75
74
let buf = ''
76
75
stream . on ( 'data' , function ( data ) { buf += data } )
77
- return BB . join (
76
+ return Promise . all ( [
78
77
finished ( stream ) . then ( ( ) => Buffer . from ( buf ) ) ,
79
- read ( CACHE , INTEGRITY ) ,
80
- ( fromStream , fromBulk ) => {
78
+ read ( CACHE , INTEGRITY ) ] )
79
+ . then ( ( [ fromStream , fromBulk ] ) => {
81
80
t . deepEqual ( fromStream , CONTENT , 'stream used algorithm' )
82
81
t . deepEqual ( fromBulk , CONTENT , 'promise used algorithm' )
83
- }
84
- )
82
+ } )
85
83
} )
86
84
87
85
test ( 'read: errors if content missing' , function ( t ) {
@@ -92,14 +90,23 @@ test('read: errors if content missing', function (t) {
92
90
stream . on ( 'end' , function ( ) {
93
91
throw new Error ( 'end was called even though stream errored' )
94
92
} )
95
- return BB . join (
96
- finished ( stream ) . catch ( { code : 'ENOENT' } , err => err ) ,
97
- read ( CACHE , 'sha512-whatnot' ) . catch ( { code : 'ENOENT' } , err => err ) ,
98
- ( streamErr , bulkErr ) => {
93
+ return Promise . all ( [
94
+ finished ( stream ) . catch ( ( err ) => {
95
+ if ( err . code === 'ENOENT' ) {
96
+ return err
97
+ }
98
+ throw err
99
+ } ) ,
100
+ read ( CACHE , 'sha512-whatnot' ) . catch ( ( err ) => {
101
+ if ( err . code === 'ENOENT' ) {
102
+ return err
103
+ }
104
+ throw err
105
+ } ) ] )
106
+ . then ( ( [ streamErr , bulkErr ] ) => {
99
107
t . equal ( streamErr . code , 'ENOENT' , 'stream got the right error' )
100
108
t . equal ( bulkErr . code , 'ENOENT' , 'bulk got the right error' )
101
- }
102
- )
109
+ } )
103
110
} )
104
111
105
112
test ( 'read: errors if content fails checksum' , function ( t ) {
@@ -113,14 +120,23 @@ test('read: errors if content fails checksum', function (t) {
113
120
stream . on ( 'end' , function ( ) {
114
121
throw new Error ( 'end was called even though stream errored' )
115
122
} )
116
- return BB . join (
117
- finished ( stream ) . catch ( { code : 'EINTEGRITY' } , err => err ) ,
118
- read ( CACHE , INTEGRITY ) . catch ( { code : 'EINTEGRITY' } , err => err ) ,
119
- ( streamErr , bulkErr ) => {
123
+ return Promise . all ( [
124
+ finished ( stream ) . catch ( ( err ) => {
125
+ if ( err . code === 'EINTEGRITY' ) {
126
+ return err
127
+ }
128
+ throw err
129
+ } ) ,
130
+ read ( CACHE , INTEGRITY ) . catch ( ( err ) => {
131
+ if ( err . code === 'EINTEGRITY' ) {
132
+ return err
133
+ }
134
+ throw err
135
+ } ) ] )
136
+ . then ( ( [ streamErr , bulkErr ] ) => {
120
137
t . equal ( streamErr . code , 'EINTEGRITY' , 'stream got the right error' )
121
138
t . equal ( bulkErr . code , 'EINTEGRITY' , 'bulk got the right error' )
122
- }
123
- )
139
+ } )
124
140
} )
125
141
126
142
test ( 'read: errors if content size does not match size option' , function ( t ) {
@@ -134,24 +150,33 @@ test('read: errors if content size does not match size option', function (t) {
134
150
stream . on ( 'end' , function ( ) {
135
151
throw new Error ( 'end was called even though stream errored' )
136
152
} )
137
- return BB . join (
138
- finished ( stream ) . catch ( { code : 'EBADSIZE' } , err => err ) ,
153
+ return Promise . all ( [
154
+ finished ( stream ) . catch ( ( err ) => {
155
+ if ( err . code === 'EBADSIZE' ) {
156
+ return err
157
+ }
158
+ throw err
159
+ } ) ,
139
160
read ( CACHE , INTEGRITY , {
140
161
size : CONTENT . length
141
- } ) . catch ( { code : 'EBADSIZE' } , err => err ) ,
142
- ( streamErr , bulkErr ) => {
162
+ } ) . catch ( ( err ) => {
163
+ if ( err . code === 'EBADSIZE' ) {
164
+ return err
165
+ }
166
+ throw err
167
+ } ) ] )
168
+ . then ( ( [ streamErr , bulkErr ] ) => {
143
169
t . equal ( streamErr . code , 'EBADSIZE' , 'stream got the right error' )
144
170
t . equal ( bulkErr . code , 'EBADSIZE' , 'bulk got the right error' )
145
- }
146
- )
171
+ } )
147
172
} )
148
173
149
174
test ( 'hasContent: tests content existence' , t => {
150
175
const fixture = new Tacks ( CacheContent ( {
151
176
'sha1-deadbeef' : ''
152
177
} ) )
153
178
fixture . create ( CACHE )
154
- return BB . join (
179
+ return Promise . all ( [
155
180
read . hasContent ( CACHE , 'sha1-deadbeef' )
156
181
. then ( content => {
157
182
t . ok ( content . sri , 'returned sri for this content' )
@@ -166,7 +191,7 @@ test('hasContent: tests content existence', t => {
166
191
. then ( content => {
167
192
t . equal ( content , false , 'multi-content hash failures work ok' )
168
193
} )
169
- )
194
+ ] )
170
195
} )
171
196
172
197
test ( 'hasContent.sync: checks content existence synchronously' , t => {
0 commit comments