@@ -151,6 +151,40 @@ test('delete.sync: removes a cache entry', (t) => {
151
151
} )
152
152
} )
153
153
154
+ test ( 'delete.sync: removeFully deletes the index entirely' , async ( t ) => {
155
+ const bucket = index . bucketPath ( CACHE , KEY )
156
+ await index . insert ( CACHE , KEY , INTEGRITY )
157
+ const entries = await index . bucketEntries ( bucket )
158
+ t . equal ( entries . length , 1 , 'has an entry' )
159
+
160
+ // do a normal delete first, this appends a null integrity
161
+ index . delete . sync ( CACHE , KEY )
162
+ const delEntries = await index . bucketEntries ( bucket )
163
+ t . equal ( delEntries . length , 2 , 'should now have 2 entries' )
164
+ t . equal ( delEntries [ 1 ] . integrity , null , 'has a null integrity last' )
165
+
166
+ // then a full delete
167
+ index . delete . sync ( CACHE , KEY , { removeFully : true } )
168
+ await t . rejects ( index . bucketEntries ( bucket ) , { code : 'ENOENT' } , 'rejects with ENOENT because file is gone' )
169
+ } )
170
+
171
+ test ( 'delete: removeFully deletes the index entirely' , async ( t ) => {
172
+ const bucket = index . bucketPath ( CACHE , KEY )
173
+ await index . insert ( CACHE , KEY , INTEGRITY )
174
+ const entries = await index . bucketEntries ( bucket )
175
+ t . equal ( entries . length , 1 , 'has an entry' )
176
+
177
+ // do a normal delete first, this appends a null integrity
178
+ await index . delete ( CACHE , KEY )
179
+ const delEntries = await index . bucketEntries ( bucket )
180
+ t . equal ( delEntries . length , 2 , 'should now have 2 entries' )
181
+ t . equal ( delEntries [ 1 ] . integrity , null , 'has a null integrity last' )
182
+
183
+ // then a full delete
184
+ await index . delete ( CACHE , KEY , { removeFully : true } )
185
+ await t . rejects ( index . bucketEntries ( bucket ) , { code : 'ENOENT' } , 'rejects with ENOENT because file is gone' )
186
+ } )
187
+
154
188
test ( 'find: error on parsing json data' , ( t ) => {
155
189
// mocks readFile in order to return a borked json payload
156
190
const { find } = getEntryIndex ( {
0 commit comments