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 pathchmod.js
62 lines (47 loc) · 1.54 KB
/
chmod.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
/* eslint-env mocha */
'use strict'
const hat = require('hat')
const { getDescribe, getIt, expect } = require('../utils/mocha')
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.files.chmod', function () {
this.timeout(40 * 1000)
let ipfs
async function testMode (mode, expectedMode) {
const testPath = `/test-${hat()}`
await ipfs.files.write(testPath, Buffer.from('Hello, world!'), {
create: true
})
await ipfs.files.chmod(testPath, mode)
const stat = await ipfs.files.stat(testPath)
expect(stat).to.have.property('mode').that.equals(expectedMode)
}
before(async () => {
ipfs = (await common.spawn()).api
})
after(() => common.clean())
it('should change file mode', async function () {
const mode = parseInt('544', 8)
await testMode(mode, mode)
})
it('should change file mode as string', async function () {
const mode = parseInt('544', 8)
await testMode('544', mode)
})
it('should change file mode to 0', async function () {
const mode = 0
await testMode(mode, mode)
})
it('should change directory mode', async function () {
const testPath = `/test-${hat()}`
const mode = parseInt('544', 8)
await ipfs.files.mkdir(testPath, {
create: true
})
await ipfs.files.chmod(testPath, mode)
const stat = await ipfs.files.stat(testPath)
expect(stat).to.have.property('mode').that.equals(mode)
})
})
}