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

Get tests passing with pin core changes (#63) #160

Merged
merged 2 commits into from
Oct 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 70 additions & 51 deletions src/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const expect = chai.expect
chai.use(dirtyChai)
const loadFixture = require('aegir/fixtures')

const testfile = loadFixture(__dirname, '../test/fixtures/testfile.txt', 'interface-ipfs-core')
const testFile = loadFixture(__dirname, '../test/fixtures/testfile.txt', 'interface-ipfs-core')
const testHash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

module.exports = (common) => {
describe('.pin', function () {
Expand All @@ -28,14 +29,11 @@ module.exports = (common) => {
})

function populate () {
const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

ipfs.files.add(testfile, (err, res) => {
ipfs.files.add(testFile, (err, res) => {
expect(err).to.not.exist()

expect(res).to.have.length(1)
expect(res[0].hash).to.equal(expectedMultihash)
expect(res[0].path).to.equal(expectedMultihash)
expect(res[0].hash).to.equal(testHash)
expect(res[0].path).to.equal(testHash)
done()
})
}
Expand All @@ -47,109 +45,130 @@ module.exports = (common) => {

describe('callback API', () => {
// 1st, because ipfs.files.add pins automatically
it('.rm', (done) => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

ipfs.pin.rm(hash, { recursive: true }, (err, pinset) => {
it('.ls type recursive', (done) => {
ipfs.pin.ls({ type: 'recursive' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.exist()
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.be.empty()
done()
expect(pinset).to.deep.include({
hash: testHash,
type: 'recursive'
})
done()
})
})

it('.add', (done) => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

ipfs.pin.add(hash, { recursive: false }, (err, pinset) => {
it.skip('.ls type indirect', (done) => {
ipfs.pin.ls({ type: 'indirect' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset[0]).to.be.equal(hash)
// because the pinned file has no links
expect(pinset).to.be.empty()
done()
})
})

it('.ls', (done) => {
ipfs.pin.ls((err, pinset) => {
it('.rm', (done) => {
ipfs.pin.rm(testHash, { recursive: true }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.be.empty()
done()
expect(pinset).to.deep.equal([{
hash: testHash
}])
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.deep.include({
hash: testHash,
type: 'recursive'
})
done()
})
})
})

it('.ls type direct', (done) => {
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
it('.add', (done) => {
ipfs.pin.add(testHash, { recursive: false }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.be.empty()
expect(pinset).to.deep.equal([{
hash: testHash
}])
done()
})
})

it('.ls type indirect', (done) => {
ipfs.pin.ls({ type: 'indirect' }, (err, pinset) => {
it('.ls', (done) => {
ipfs.pin.ls((err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.be.empty()
expect(pinset).to.deep.include({
hash: testHash,
type: 'direct'
})
done()
})
})

it('.ls type recursive', (done) => {
ipfs.pin.ls({ type: 'recursive' }, (err, pinset) => {
it('.ls type direct', (done) => {
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.not.be.empty()
expect(pinset).to.deep.include({
hash: testHash,
type: 'direct'
})
done()
})
})

it('.ls for a specific hash', (done) => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

ipfs.pin.ls(hash, (err, pinset) => {
ipfs.pin.ls(testHash, (err, pinset) => {
expect(err).to.not.exist()
expect(pinset).to.exist()
expect(pinset).to.deep.equal([{
hash: testHash,
type: 'direct'
}])
done()
})
})
})

describe('promise API', () => {
it('.add', () => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

return ipfs.pin.add(hash, { recursive: false })
return ipfs.pin.add(testHash, { recursive: false })
.then((pinset) => {
expect(pinset[0]).to.be.equal(hash)
expect(pinset).to.deep.equal([{
hash: testHash
}])
})
})

it('.ls', () => {
return ipfs.pin.ls()
.then((pinset) => {
expect(pinset).to.exist()
expect(pinset).to.not.be.empty()
expect(pinset).to.deep.include({
hash: testHash,
type: 'direct'
})
})
})

it('.ls hash', () => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

return ipfs.pin.ls(hash)
return ipfs.pin.ls(testHash)
.then((pinset) => {
expect(pinset).to.exist()
expect(pinset).to.deep.equal([{
hash: testHash,
type: 'direct'
}])
})
})

it('.rm', () => {
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

return ipfs.pin.rm(hash, { recursive: false })
return ipfs.pin.rm(testHash, { recursive: false })
.then((pinset) => {
expect(pinset).to.deep.equal([{
hash: testHash
}])
return ipfs.pin.ls({ type: 'direct' })
})
.then((pinset) => {
expect(pinset).to.be.empty()
expect(pinset).to.not.deep.include({
hash: testHash
})
})
})
})
Expand Down