This repository was 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.2k
/
Copy pathrm.js
78 lines (61 loc) · 2.38 KB
/
rm.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
77
78
/* eslint-env mocha */
import { fixtures, expectPinned, clearPins } from './utils.js'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import all from 'it-all'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testRm (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.pin.rm', function () {
this.timeout(50 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
beforeEach(async () => {
ipfs = (await factory.spawn()).api
const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data }))
await all(ipfs.addAll(dir, { pin: false, cidVersion: 0 }))
await ipfs.add(fixtures.files[0].data, { pin: false })
await ipfs.add(fixtures.files[1].data, { pin: false })
})
after(() => factory.clean())
beforeEach(() => {
return clearPins(ipfs)
})
it('should remove a recursive pin', async () => {
await ipfs.pin.add(fixtures.directory.cid)
const unpinnedCid = await ipfs.pin.rm(fixtures.directory.cid, { recursive: true })
expect(unpinnedCid).to.deep.equal(fixtures.directory.cid)
const pinset = await all(ipfs.pin.ls({ type: 'recursive' }))
expect(pinset).to.not.deep.include({
cid: fixtures.directory.cid,
type: 'recursive'
})
})
it('should remove a direct pin', async () => {
await ipfs.pin.add(fixtures.directory.cid, { recursive: false })
const unpinnedCid = await ipfs.pin.rm(fixtures.directory.cid, { recursive: false })
expect(unpinnedCid).to.deep.equal(fixtures.directory.cid)
const pinset = await all(ipfs.pin.ls({ type: 'direct' }))
expect(pinset.map(p => p.cid)).to.not.deep.include(fixtures.directory.cid)
})
it('should fail to remove an indirect pin', async () => {
await ipfs.pin.add(fixtures.directory.cid, {
recursive: true
})
await expect(ipfs.pin.rm(fixtures.directory.files[0].cid))
.to.eventually.be.rejectedWith(/pinned indirectly/)
await expectPinned(ipfs, fixtures.directory.files[0].cid)
})
it('should fail when an item is not pinned', async () => {
await expect(ipfs.pin.rm(fixtures.directory.cid))
.to.eventually.be.rejectedWith(/not pinned/)
})
})
}