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

Commit

Permalink
feat: additional tests for indirect pin.ls
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Jul 9, 2019
1 parent e8955b1 commit b791922
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
64 changes: 40 additions & 24 deletions src/pin/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,18 @@ module.exports = (createCommon, options) => {

function populate () {
series([
cb => { // two files wrapped in a directory, root CID pinned recursively
// two files wrapped in directories, only root CID pinned recursively
cb => {
const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data }))
ipfs.files.add(dir, { pin: false }, (err, res) => {
if (err) return cb(err)
ipfs.pin.add(fixtures.directory.cid, { recursive: true }, cb)
})
ipfs.add(dir, { pin: false, cidVersion: 0 }, cb)
},
cb => { // a file (CID pinned recursively)
ipfs.files.add(fixtures.files[0].data, { pin: false }, (err, res) => {
if (err) return cb(err)
ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb)
})
},
cb => { // a single CID (pinned directly)
ipfs.files.add(fixtures.files[1].data, { pin: false }, (err, res) => {
if (err) return cb(err)
ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
})
}
cb => ipfs.pin.add(fixtures.directory.cid, { recursive: true }, cb),
// a file (CID pinned recursively)
cb => ipfs.add(fixtures.files[0].data, { pin: false, cidVersion: 0 }, cb),
cb => ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb),
// a single CID (pinned directly)
cb => ipfs.add(fixtures.files[1].data, { pin: false, cidVersion: 0 }, cb),
cb => ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
], done)
}
})
Expand Down Expand Up @@ -87,6 +80,14 @@ module.exports = (createCommon, options) => {
type: 'recursive',
hash: fixtures.directory.cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[0].cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[1].cid
})
done()
})
})
Expand All @@ -95,7 +96,6 @@ module.exports = (createCommon, options) => {
ipfs.pin.ls((err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.be.empty()
expect(pinset).to.have.lengthOf(15)
// check the three "roots"
expect(pinset).to.deep.include({
type: 'recursive',
Expand All @@ -109,6 +109,14 @@ module.exports = (createCommon, options) => {
type: 'direct',
hash: fixtures.files[1].cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[0].cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[1].cid
})
done()
})
})
Expand All @@ -117,7 +125,6 @@ module.exports = (createCommon, options) => {
return ipfs.pin.ls()
.then((pinset) => {
expect(pinset).to.not.be.empty()
expect(pinset).to.have.lengthOf(15)
// check our three "roots"
expect(pinset).to.deep.include({
type: 'recursive',
Expand All @@ -131,12 +138,21 @@ module.exports = (createCommon, options) => {
type: 'direct',
hash: fixtures.files[1].cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[0].cid
})
expect(pinset).to.deep.include({
type: 'indirect',
hash: fixtures.directory.files[1].cid
})
})
})

it('should list all direct pins', (done) => {
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.have.lengthOf(1)
expect(pinset).to.deep.include({
type: 'direct',
hash: fixtures.files[1].cid
Expand Down Expand Up @@ -166,21 +182,21 @@ module.exports = (createCommon, options) => {
})
})

it('should throw an error on missing direct pins for a specific path', (done) => {
// alice.txt is an indirect pin, so lookup for direct one should throw an error
it('should throw an error on missing direct pins for existing path', (done) => {
// ipfs.txt is an indirect pin, so lookup for direct one should throw an error
ipfs.pin.ls(`/ipfs/${fixtures.directory.cid}/files/ipfs.txt`, { type: 'direct' }, (err, pinset) => {
expect(err).to.exist()
expect(pinset).to.not.exist()
expect(err).to.not.be.empty()
expect(err.message).to.be.equal(`path '/ipfs/${fixtures.directory.cid}/files/ipfs.txt' is not pinned`)
done()
})
})

it('should throw an error on missing link for a specific path', (done) => {
ipfs.pin.ls(`/ipfs/${fixtures.directory.cid}/I-DONT-EXIST.txt`, { type: 'direct' }, (err, pinset) => {
expect(err).to.exist()
expect(pinset).to.not.exist()
expect(err).to.not.be.empty()
expect(err.message).to.be.equal('no link by that name')
expect(err.message).to.be.equal(`no link named "I-DONT-EXIST.txt" under ${fixtures.directory.cid}`)
done()
})
})
Expand Down
9 changes: 5 additions & 4 deletions src/pin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
const loadFixture = require('aegir/fixtures')

exports.fixtures = Object.freeze({
// NOTE: files under 'directory' need to be different than standalone ones in 'files'
directory: Object.freeze({
cid: 'QmVJV2VF9Qf7rJUFdimhpZDhkyyumM1i4CjjGcss5rqJPa',
cid: 'QmY8KdYQSYKFU5hM7F5ioZ5yYSgV5VZ1kDEdqfRL3rFgcd',
files: Object.freeze([Object.freeze({
path: 'test-folder/ipfs-add.js',
data: loadFixture('js/test/fixtures/test-folder/ipfs-add.js', 'interface-ipfs-core'),
cid: 'QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL'
data: loadFixture('test/fixtures/test-folder/ipfs-add.js', 'interface-ipfs-core'),
cid: 'QmbKtKBrmeRHjNCwR4zAfCJdMVu6dgmwk9M9AE9pUM9RgG'
}), Object.freeze({
path: 'test-folder/files/ipfs.txt',
data: loadFixture('js/test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core'),
data: loadFixture('test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core'),
cid: 'QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w'
})])
}),
Expand Down

0 comments on commit b791922

Please sign in to comment.