|
3 | 3 | const BB = require('bluebird')
|
4 | 4 |
|
5 | 5 | const CacheIndex = require('./util/cache-index')
|
| 6 | +const contentPath = require('../lib/content/path') |
6 | 7 | const finished = BB.promisify(require('mississippi').finished)
|
| 8 | +const index = require('../lib/entry-index.js') |
7 | 9 | const path = require('path')
|
8 | 10 | const Tacks = require('tacks')
|
9 | 11 | const test = require('tap').test
|
10 | 12 | const testDir = require('./util/test-dir')(__filename)
|
11 | 13 |
|
12 | 14 | const CACHE = path.join(testDir, 'cache')
|
13 |
| -const contentPath = require('../lib/content/path') |
14 | 15 | const File = Tacks.File
|
15 | 16 |
|
16 | 17 | const ls = require('..').ls
|
@@ -111,3 +112,58 @@ test('ignores non-dir files', function (t) {
|
111 | 112 | t.equal(listing.whatever.key, 'whatever', 'only the correct entry listed')
|
112 | 113 | })
|
113 | 114 | })
|
| 115 | + |
| 116 | +test('correctly ignores deleted entries', t => { |
| 117 | + const contents = { |
| 118 | + 'whatever': { |
| 119 | + key: 'whatever', |
| 120 | + integrity: 'sha512-deadbeef', |
| 121 | + time: 12345, |
| 122 | + metadata: 'omgsometa', |
| 123 | + size: 234234 |
| 124 | + }, |
| 125 | + 'whatnot': { |
| 126 | + key: 'whatnot', |
| 127 | + integrity: 'sha512-bada55', |
| 128 | + time: 54321, |
| 129 | + metadata: null, |
| 130 | + size: 425345345 |
| 131 | + }, |
| 132 | + 'whatwhere': { |
| 133 | + key: 'whatwhere', |
| 134 | + integrity: 'sha512-bada55e5', |
| 135 | + time: 54321, |
| 136 | + metadata: null, |
| 137 | + size: 425345345 |
| 138 | + } |
| 139 | + } |
| 140 | + const fixture = new Tacks(CacheIndex(contents)) |
| 141 | + contents.whatever.path = |
| 142 | + contentPath( |
| 143 | + CACHE, contents.whatever.integrity) |
| 144 | + contents.whatnot.path = |
| 145 | + contentPath( |
| 146 | + CACHE, contents.whatnot.integrity) |
| 147 | + contents.whatwhere.path = |
| 148 | + contentPath( |
| 149 | + CACHE, contents.whatwhere.integrity) |
| 150 | + fixture.create(CACHE) |
| 151 | + return index.delete(CACHE, 'whatnot') |
| 152 | + .then(() => ls(CACHE)) |
| 153 | + .then(listing => t.deepEqual(listing, { |
| 154 | + whatever: contents.whatever, |
| 155 | + whatwhere: contents.whatwhere |
| 156 | + }, 'index contents correct')) |
| 157 | + .then(() => { |
| 158 | + const listing = [] |
| 159 | + const stream = ls.stream(CACHE) |
| 160 | + stream.on('data', entry => { |
| 161 | + listing[entry.key] = entry |
| 162 | + }) |
| 163 | + return finished(stream) |
| 164 | + .then(() => t.deepEqual(listing, { |
| 165 | + whatever: contents.whatever, |
| 166 | + whatwhere: contents.whatwhere |
| 167 | + }, 'ls is streamable')) |
| 168 | + }) |
| 169 | +}) |
0 commit comments