Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 761fcee

Browse files
committed
add tests for ipfs files stat --with-local
1 parent 271d44d commit 761fcee

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

js/src/files-mfs.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ module.exports = (common) => {
276276
blocks: 1,
277277
size: 13,
278278
hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T',
279-
cumulativeSize: 71
279+
cumulativeSize: 71,
280+
withLocality: false,
281+
local: undefined,
282+
sizeLocal: undefined
280283
})
281284
done()
282285
})
@@ -295,7 +298,54 @@ module.exports = (common) => {
295298
blocks: 2,
296299
size: 0,
297300
hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto',
298-
cumulativeSize: 216
301+
cumulativeSize: 216,
302+
withLocality: false,
303+
local: undefined,
304+
sizeLocal: undefined
305+
})
306+
done()
307+
})
308+
})
309+
310+
it('stat withLocal file', function (done) {
311+
if (!withGo) {
312+
console.log('Not supported in js-ipfs yet')
313+
this.skip()
314+
}
315+
316+
ipfs.files.stat('/test/b', {'withLocal': true}, (err, stat) => {
317+
expect(err).to.not.exist()
318+
expect(stat).to.eql({
319+
type: 'file',
320+
blocks: 1,
321+
size: 13,
322+
hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T',
323+
cumulativeSize: 71,
324+
withLocality: true,
325+
local: true,
326+
sizeLocal: 71
327+
})
328+
done()
329+
})
330+
})
331+
332+
it('stat withLocal dir', function (done) {
333+
if (!withGo) {
334+
console.log('Not supported in js-ipfs yet')
335+
this.skip()
336+
}
337+
338+
ipfs.files.stat('/test', {'withLocal': true}, (err, stat) => {
339+
expect(err).to.not.exist()
340+
expect(stat).to.eql({
341+
type: 'directory',
342+
blocks: 2,
343+
size: 0,
344+
hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto',
345+
cumulativeSize: 216,
346+
withLocality: true,
347+
local: true,
348+
sizeLocal: 216
299349
})
300350
done()
301351
})

js/src/files.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = (common) => {
2424
this.timeout(40 * 1000)
2525

2626
let ipfs
27+
let withGo
2728

2829
function fixture (path) {
2930
return loadFixture(path, 'interface-ipfs-core')
@@ -60,7 +61,11 @@ module.exports = (common) => {
6061
factory.spawnNode((err, node) => {
6162
expect(err).to.not.exist()
6263
ipfs = node
63-
done()
64+
node.id((err, id) => {
65+
expect(err).to.not.exist()
66+
withGo = id.agentVersion.startsWith('go-ipfs')
67+
done()
68+
})
6469
})
6570
})
6671
})
@@ -980,5 +985,31 @@ module.exports = (common) => {
980985
)
981986
})
982987
})
988+
989+
describe('.stat', () => {
990+
before((done) => ipfs.files.add(smallFile.data, done))
991+
992+
it('stat outside of mfs', function (done) {
993+
if (!withGo) {
994+
console.log('Not supported in js-ipfs yet')
995+
this.skip()
996+
}
997+
998+
ipfs.files.stat('/ipfs/' + smallFile.cid, (err, stat) => {
999+
expect(err).to.not.exist()
1000+
expect(stat).to.eql({
1001+
type: 'file',
1002+
blocks: 0,
1003+
size: 12,
1004+
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
1005+
cumulativeSize: 20,
1006+
withLocality: false,
1007+
local: undefined,
1008+
sizeLocal: undefined
1009+
})
1010+
done()
1011+
})
1012+
})
1013+
})
9831014
})
9841015
}

0 commit comments

Comments
 (0)