Skip to content

Commit 0b7faf6

Browse files
authored
fix(coverage): bumping coverage for verify (#71)
1 parent cac5f9c commit 0b7faf6

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

Diff for: lib/verify.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ const rimraf = BB.promisify(require('rimraf'))
1515

1616
BB.promisifyAll(fs)
1717

18-
module.exports.lastRun = lastRun
19-
function lastRun (cache) {
20-
return fs.readFileAsync(
21-
path.join(cache, '_lastverified'), 'utf8'
22-
).then(data => new Date(+data))
23-
}
24-
2518
module.exports = verify
2619
function verify (cache, opts) {
2720
opts = opts || {}
@@ -211,3 +204,10 @@ function writeVerifile (cache, opts) {
211204
opts.log && opts.log.silly('verify', 'writing verifile to ' + verifile)
212205
return fs.writeFileAsync(verifile, '' + (+(new Date())))
213206
}
207+
208+
module.exports.lastRun = lastRun
209+
function lastRun (cache) {
210+
return fs.readFileAsync(
211+
path.join(cache, '_lastverified'), 'utf8'
212+
).then(data => new Date(+data))
213+
}

Diff for: test/verify.js

+64-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ function mockCache () {
2929
[DIGEST]: CONTENT
3030
}, ALGO))
3131
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+
})
3537
})
3638
}
3739

@@ -149,6 +151,63 @@ test('removes corrupted content', t => {
149151
})
150152
})
151153

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+
153213
test('fixes permissions and users on cache contents')
154-
test('cleans up contents of tmp dir')

0 commit comments

Comments
 (0)