@@ -29,9 +29,11 @@ function mockCache () {
29
29
[ DIGEST ] : CONTENT
30
30
} , ALGO ) )
31
31
fixture . create ( CACHE )
32
- return index . insert ( CACHE , KEY , DIGEST , {
33
- metadata : METADATA ,
34
- hashAlgorithm : ALGO
32
+ return fs . mkdirAsync ( path . join ( CACHE , 'tmp' ) ) . then ( ( ) => {
33
+ return index . insert ( CACHE , KEY , DIGEST , {
34
+ metadata : METADATA ,
35
+ hashAlgorithm : ALGO
36
+ } )
35
37
} )
36
38
}
37
39
@@ -149,6 +151,63 @@ test('removes corrupted content', t => {
149
151
} )
150
152
} )
151
153
152
- test ( 'removes content not referenced by any entries' )
154
+ test ( 'removes content not referenced by any entries' , t => {
155
+ const fixture = new Tacks ( CacheContent ( {
156
+ [ DIGEST ] : CONTENT
157
+ } , ALGO ) )
158
+ fixture . create ( CACHE )
159
+ return verify ( CACHE ) . then ( stats => {
160
+ delete stats . startTime
161
+ delete stats . runTime
162
+ delete stats . endTime
163
+ t . deepEqual ( stats , {
164
+ verifiedContent : 0 ,
165
+ reclaimedCount : 1 ,
166
+ reclaimedSize : CONTENT . length ,
167
+ badContentCount : 0 ,
168
+ keptSize : 0 ,
169
+ missingContent : 0 ,
170
+ rejectedEntries : 0 ,
171
+ totalEntries : 0
172
+ } , 'reported correct collection counts' )
173
+ } )
174
+ } )
175
+
176
+ test ( 'cleans up contents of tmp dir' , t => {
177
+ const tmpFile = path . join ( CACHE , 'tmp' , 'x' )
178
+ const misc = path . join ( CACHE , 'y' )
179
+ return mockCache ( ) . then ( ( ) => {
180
+ return BB . join (
181
+ fs . writeFileAsync ( tmpFile , '' ) ,
182
+ fs . writeFileAsync ( misc , '' ) ,
183
+ ( ) => verify ( CACHE )
184
+ )
185
+ } ) . then ( ( ) => {
186
+ return BB . join (
187
+ fs . statAsync ( tmpFile ) . catch ( { code : 'ENOENT' } , e => e ) ,
188
+ fs . statAsync ( misc ) ,
189
+ ( err , stat ) => {
190
+ t . equal ( err . code , 'ENOENT' , 'tmp file was blown away' )
191
+ t . ok ( stat , 'misc file was not touched' )
192
+ }
193
+ )
194
+ } )
195
+ } )
196
+
197
+ test ( 'writes a file with last verification time' , t => {
198
+ return verify ( CACHE ) . then ( ( ) => {
199
+ return BB . join (
200
+ verify . lastRun ( CACHE ) ,
201
+ fs . readFileAsync (
202
+ path . join ( CACHE , '_lastverified' ) , 'utf8'
203
+ ) . then ( data => {
204
+ return new Date ( parseInt ( data ) )
205
+ } ) ,
206
+ ( fromLastRun , fromFile ) => {
207
+ t . equal ( + fromLastRun , + fromFile , 'last verified was writen' )
208
+ }
209
+ )
210
+ } )
211
+ } )
212
+
153
213
test ( 'fixes permissions and users on cache contents' )
154
- test ( 'cleans up contents of tmp dir' )
0 commit comments