This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathrm.js
55 lines (39 loc) · 1.53 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
/* eslint-env mocha */
'use strict'
const hat = require('hat')
const all = require('it-all')
const { getDescribe, getIt, expect } = require('../utils/mocha')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.files.rm', function () {
this.timeout(40 * 1000)
let ipfs
before(async () => { ipfs = (await common.spawn()).api })
after(() => common.clean())
it('should not remove not found file/dir, expect error', () => {
const testDir = `/test-${hat()}`
return expect(ipfs.files.rm(`${testDir}/a`)).to.eventually.be.rejected()
})
it('should remove file, expect no error', async () => {
const testDir = `/test-${hat()}`
await ipfs.files.mkdir(testDir, { parents: true })
await ipfs.files.write(`${testDir}/c`, Buffer.from('Hello, world!'), { create: true })
await ipfs.files.rm(`${testDir}/c`)
const contents = await all(ipfs.files.ls(testDir))
expect(contents).to.be.an('array').and.to.be.empty()
})
it('should remove dir, expect no error', async () => {
const testDir = `/test-${hat()}`
await ipfs.files.mkdir(`${testDir}/lv1/lv2`, { parents: true })
await ipfs.files.rm(`${testDir}/lv1/lv2`, { recursive: true })
const lv1Contents = await all(ipfs.files.ls(`${testDir}/lv1`))
expect(lv1Contents).to.be.an('array').and.to.be.empty()
})
})
}