diff --git a/src/files-mfs/stat.js b/src/files-mfs/stat.js index d768adf2d..2f03eb5bd 100644 --- a/src/files-mfs/stat.js +++ b/src/files-mfs/stat.js @@ -19,7 +19,11 @@ module.exports = (common, options) => { let ipfs - before(async () => { ipfs = (await common.spawn()).api }) + before(async () => { + ipfs = (await common.spawn({ + args: common.opts.type === 'go' ? [] : ['--enable-sharding-experiment'] + })).api + }) before(async () => { await ipfs.add(fixtures.smallFile.data) }) after(() => common.clean()) @@ -50,6 +54,41 @@ module.exports = (common, options) => { expect(stat.sizeLocal).to.be.undefined() }) + it('should stat file with mode', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { parents: true }) + await ipfs.files.write(`${testDir}/b`, Buffer.from('Hello, world!'), { create: true }) + + const stat = await ipfs.files.stat(`${testDir}/b`) + + expect(stat).to.include({ + mode: 0o644 + }) + }) + + it('should stat file with mtime', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { parents: true }) + await ipfs.files.write(`${testDir}/b`, Buffer.from('Hello, world!'), { + create: true, + mtime: { + secs: 5, + nsecs: 0 + } + }) + + const stat = await ipfs.files.stat(`${testDir}/b`) + + expect(stat).to.deep.include({ + mtime: { + secs: 5, + nsecs: 0 + } + }) + }) + it('should stat dir', async function () { const testDir = `/test-${hat()}` @@ -68,6 +107,81 @@ module.exports = (common, options) => { expect(stat.sizeLocal).to.be.undefined() }) + it('should stat dir with mode', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { parents: true }) + const stat = await ipfs.files.stat(testDir) + + expect(stat).to.include({ + mode: 0o755 + }) + }) + + it('should stat dir with mtime', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { + parents: true, + mtime: { + secs: 5, + nsecs: 0 + } + }) + + const stat = await ipfs.files.stat(testDir) + + expect(stat).to.deep.include({ + mtime: { + secs: 5, + nsecs: 0 + } + }) + }) + + it('should stat sharded dir with mode', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { parents: true }) + await ipfs.files.write(`${testDir}/a`, Buffer.from('Hello, world!'), { + create: true, + shardSplitThreshold: 0 + }) + + const stat = await ipfs.files.stat(testDir) + + expect(stat).to.have.property('type', 'hamt-sharded-directory') + expect(stat).to.include({ + mode: 0o755 + }) + }) + + it('should stat sharded dir with mtime', async function () { + const testDir = `/test-${hat()}` + + await ipfs.files.mkdir(testDir, { + parents: true, + mtime: { + secs: 5, + nsecs: 0 + } + }) + await ipfs.files.write(`${testDir}/a`, Buffer.from('Hello, world!'), { + create: true, + shardSplitThreshold: 0 + }) + + const stat = await ipfs.files.stat(testDir) + + expect(stat).to.have.property('type', 'hamt-sharded-directory') + expect(stat).to.deep.include({ + mtime: { + secs: 5, + nsecs: 0 + } + }) + }) + // TODO enable this test when this feature gets released on go-ipfs it.skip('should stat withLocal file', async function () { const stat = await ipfs.files.stat('/test/b', { withLocal: true }) diff --git a/src/files-regular/add-pull-stream.js b/src/files-regular/add-pull-stream.js index dd408114c..003f3f984 100644 --- a/src/files-regular/add-pull-stream.js +++ b/src/files-regular/add-pull-stream.js @@ -59,7 +59,7 @@ module.exports = (common, options) => { const res = await pullToPromise.any(pull(pull.values(data), stream)) expect(res).to.have.property('length', 1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.include({ path: expectedCid, hash: expectedCid, size: 12 }) }) }) } diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 4a51c9a44..6c11e88d0 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -28,7 +28,9 @@ module.exports = (common, options) => { content: Buffer.from(content), mode }) + expect(files).to.have.length(1) + expect(files).to.have.nested.property('[0].mode', expectedMode) const stats = await ipfs.files.stat(`/ipfs/${files[0].hash}`) expect(stats).to.have.property('mode', expectedMode) @@ -41,6 +43,7 @@ module.exports = (common, options) => { mtime }) expect(files).to.have.length(1) + expect(files).to.have.deep.nested.property('[0].mtime', expectedMtime) const stats = await ipfs.files.stat(`/ipfs/${files[0].hash}`) expect(stats).to.have.deep.property('mtime', expectedMtime) @@ -197,7 +200,7 @@ module.exports = (common, options) => { const res = await ipfs.add(pull.values([Buffer.from('test')])) expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.include({ path: expectedCid, hash: expectedCid, size: 12 }) }) it('should add array of objects with pull stream content', async () => { @@ -205,7 +208,7 @@ module.exports = (common, options) => { const res = await ipfs.add([{ content: pull.values([Buffer.from('test')]) }]) expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.include({ path: expectedCid, hash: expectedCid, size: 12 }) }) it('should add a nested directory as array of tupples', async function () {