This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathrefs-local.js
76 lines (60 loc) · 1.9 KB
/
refs-local.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-env mocha */
import { fixtures } from './utils/index.js'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from './utils/mocha.js'
import all from 'it-all'
import { importer } from 'ipfs-unixfs-importer'
import drain from 'it-drain'
import { CID } from 'multiformats/cid'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import blockstore from './utils/blockstore-adapter.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testRefsLocal (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.refs.local', function () {
this.timeout(60 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
})
after(() => factory.clean())
it('should get local refs', async function () {
/**
* @param {string} name
*/
const content = (name) => ({
path: `test-folder/${name}`,
content: fixtures.directory.files[name]
})
const dirs = [
content('pp.txt'),
content('holmes.txt')
]
const imported = await all(importer(dirs, blockstore(ipfs)))
// otherwise go-ipfs doesn't show them in the local refs
await drain(ipfs.pin.addAll(imported.map(i => ({ cid: i.cid }))))
const refs = await all(ipfs.refs.local())
const cids = refs.map(r => r.ref)
expect(
cids.find(cid => {
const multihash = CID.parse(cid).multihash.bytes
return uint8ArrayEquals(imported[0].cid.multihash.bytes, multihash)
})
).to.be.ok()
expect(
cids.find(cid => {
const multihash = CID.parse(cid).multihash.bytes
return uint8ArrayEquals(imported[1].cid.multihash.bytes, multihash)
})
).to.be.ok()
})
})
}