@@ -146,7 +146,7 @@ test('read: errors if content size does not match size option', function (t) {
146
146
)
147
147
} )
148
148
149
- test ( 'hasContent: returns { sri, size } when a cache file exists ' , function ( t ) {
149
+ test ( 'hasContent: tests content existence ' , t => {
150
150
const fixture = new Tacks ( CacheContent ( {
151
151
'sha1-deadbeef' : ''
152
152
} ) )
@@ -156,6 +156,7 @@ test('hasContent: returns { sri, size } when a cache file exists', function (t)
156
156
. then ( content => {
157
157
t . ok ( content . sri , 'returned sri for this content' )
158
158
t . equal ( content . size , 0 , 'returned the right size for this content' )
159
+ t . ok ( content . stat . isFile ( ) , 'returned actual stat object' )
159
160
} ) ,
160
161
read . hasContent ( CACHE , 'sha1-not-there' )
161
162
. then ( content => {
@@ -168,6 +169,28 @@ test('hasContent: returns { sri, size } when a cache file exists', function (t)
168
169
)
169
170
} )
170
171
172
+ test ( 'hasContent.sync: checks content existence synchronously' , t => {
173
+ const fixture = new Tacks ( CacheContent ( {
174
+ 'sha1-deadbeef' : ''
175
+ } ) )
176
+ fixture . create ( CACHE )
177
+ const content = read . hasContent . sync ( CACHE , 'sha1-deadbeef' )
178
+ t . ok ( content . sri , 'returned sri for this content' )
179
+ t . equal ( content . size , 0 , 'returned the right size for this content' )
180
+ t . ok ( content . stat . isFile ( ) , 'returned actual stat object' )
181
+ t . equal (
182
+ read . hasContent . sync ( CACHE , 'sha1-not-there' ) ,
183
+ false ,
184
+ 'returned false for missing content'
185
+ )
186
+ t . equal (
187
+ read . hasContent . sync ( CACHE , 'sha1-not-here sha1-also-not-here' ) ,
188
+ false ,
189
+ 'multi-content hash failures work ok'
190
+ )
191
+ t . done ( )
192
+ } )
193
+
171
194
test ( 'copy: copies content to a destination path' , {
172
195
skip : ! fs . copyFile && 'Not supported on node versions without fs.copyFile'
173
196
} , t => {
@@ -184,3 +207,22 @@ test('copy: copies content to a destination path', {
184
207
t . deepEqual ( data , CONTENT , 'file successfully copied' )
185
208
} )
186
209
} )
210
+
211
+ test ( 'copy.sync: copies content to a destination path synchronously' , {
212
+ skip : ! fs . copyFile && 'Not supported on node versions without fs.copyFile'
213
+ } , t => {
214
+ const CONTENT = Buffer . from ( 'foobarbaz' )
215
+ const INTEGRITY = ssri . fromData ( CONTENT )
216
+ const DEST = path . join ( CACHE , 'foobar-file' )
217
+ const fixture = new Tacks ( CacheContent ( {
218
+ [ INTEGRITY ] : CONTENT
219
+ } ) )
220
+ fixture . create ( CACHE )
221
+ read . copy . sync ( CACHE , INTEGRITY , DEST )
222
+ t . deepEqual (
223
+ fs . readFileSync ( DEST ) ,
224
+ CONTENT ,
225
+ 'file successfully copied'
226
+ )
227
+ t . done ( )
228
+ } )
0 commit comments