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

Commit

Permalink
add tests for ipfs files stat --with-local
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Mar 9, 2018
1 parent 271d44d commit 761fcee
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
54 changes: 52 additions & 2 deletions js/src/files-mfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ module.exports = (common) => {
blocks: 1,
size: 13,
hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T',
cumulativeSize: 71
cumulativeSize: 71,
withLocality: false,
local: undefined,
sizeLocal: undefined
})
done()
})
Expand All @@ -295,7 +298,54 @@ module.exports = (common) => {
blocks: 2,
size: 0,
hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto',
cumulativeSize: 216
cumulativeSize: 216,
withLocality: false,
local: undefined,
sizeLocal: undefined
})
done()
})
})

it('stat withLocal file', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}

ipfs.files.stat('/test/b', {'withLocal': true}, (err, stat) => {
expect(err).to.not.exist()
expect(stat).to.eql({
type: 'file',
blocks: 1,
size: 13,
hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T',
cumulativeSize: 71,
withLocality: true,
local: true,
sizeLocal: 71
})
done()
})
})

it('stat withLocal dir', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}

ipfs.files.stat('/test', {'withLocal': true}, (err, stat) => {
expect(err).to.not.exist()
expect(stat).to.eql({
type: 'directory',
blocks: 2,
size: 0,
hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto',
cumulativeSize: 216,
withLocality: true,
local: true,
sizeLocal: 216
})
done()
})
Expand Down
33 changes: 32 additions & 1 deletion js/src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = (common) => {
this.timeout(40 * 1000)

let ipfs
let withGo

function fixture (path) {
return loadFixture(path, 'interface-ipfs-core')
Expand Down Expand Up @@ -60,7 +61,11 @@ module.exports = (common) => {
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
node.id((err, id) => {
expect(err).to.not.exist()
withGo = id.agentVersion.startsWith('go-ipfs')
done()
})
})
})
})
Expand Down Expand Up @@ -980,5 +985,31 @@ module.exports = (common) => {
)
})
})

describe('.stat', () => {
before((done) => ipfs.files.add(smallFile.data, done))

it('stat outside of mfs', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}

ipfs.files.stat('/ipfs/' + smallFile.cid, (err, stat) => {
expect(err).to.not.exist()
expect(stat).to.eql({
type: 'file',
blocks: 0,
size: 12,
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
cumulativeSize: 20,
withLocality: false,
local: undefined,
sizeLocal: undefined
})
done()
})
})
})
})
}

0 comments on commit 761fcee

Please sign in to comment.