This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,68 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
|
||
module.exports = (send) => { | ||
return { | ||
add (hash, opts, callback) { | ||
add: promisify((hash, opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = null | ||
} | ||
return send({ | ||
send({ | ||
path: 'pin/add', | ||
args: hash, | ||
qs: opts | ||
}, callback) | ||
}, | ||
remove (hash, opts, callback) { | ||
}, (err, res) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
callback(null, res.Pins) | ||
}) | ||
}), | ||
rm: promisify((hash, opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = null | ||
} | ||
return send({ | ||
send({ | ||
path: 'pin/rm', | ||
args: hash, | ||
qs: opts | ||
}, callback) | ||
}, | ||
list (type, callback) { | ||
if (typeof type === 'function') { | ||
callback = type | ||
type = null | ||
}, (err, res) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
callback(null, res.Pins) | ||
}) | ||
}), | ||
ls: promisify((hash, opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
let opts = null | ||
let hash = null | ||
|
||
if (typeof type === 'string') { | ||
opts = { type: type } | ||
} else if (type && type.hash) { | ||
hash = type.hash | ||
type.hash = null | ||
opts = type | ||
if (typeof hash === 'object') { | ||
opts = hash | ||
hash = undefined | ||
} | ||
return send({ | ||
|
||
if (typeof hash === 'function') { | ||
callback = hash | ||
hash = undefined | ||
opts = {} | ||
} | ||
|
||
send({ | ||
path: 'pin/ls', | ||
args: hash, | ||
qs: opts | ||
}, callback) | ||
} | ||
}, (err, res) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
callback(null, res.Keys) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,20 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const test = require('interface-ipfs-core') | ||
const FactoryClient = require('../factory/factory-client') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt')) | ||
let fc | ||
|
||
describe('.pin', () => { | ||
let ipfs | ||
let fc | ||
|
||
before(function (done) { | ||
this.timeout(20 * 1000) // slow CI | ||
const common = { | ||
setup: function (callback) { | ||
fc = new FactoryClient() | ||
fc.spawnNode((err, node) => { | ||
expect(err).to.not.exist | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
fc.dismantle(done) | ||
}) | ||
|
||
it('add file for testing', (done) => { | ||
const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
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) | ||
done() | ||
}) | ||
}) | ||
|
||
it('.pin.remove', (done) => { | ||
ipfs.pin.remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: true}, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
ipfs.pin.list('direct', (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
expect(res.Keys).to.be.empty | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('.pin.add', (done) => { | ||
ipfs.pin.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') | ||
done() | ||
}) | ||
}) | ||
|
||
it('.pin.list', (done) => { | ||
ipfs.pin.list((err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
done() | ||
}) | ||
}) | ||
|
||
it('.pin.list hash', (done) => { | ||
ipfs.pin.list({hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'}, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
done() | ||
}) | ||
}) | ||
|
||
describe('promise', () => { | ||
it('.pin.add', () => { | ||
return ipfs.pin | ||
.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) | ||
.then((res) => { | ||
expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') | ||
}) | ||
}) | ||
|
||
it('.pin.list', () => { | ||
return ipfs.pin.list() | ||
.then((res) => { | ||
expect(res).to.exist | ||
}) | ||
}) | ||
|
||
it('.pin.list hash', () => { | ||
return ipfs.pin.list({ | ||
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
}) | ||
.then((res) => { | ||
expect(res).to.exist | ||
}) | ||
}) | ||
|
||
it('.pin.remove', () => { | ||
return ipfs.pin | ||
.remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) | ||
.then((res) => { | ||
expect(res).to.exist | ||
return ipfs.pin.list('direct') | ||
}) | ||
.then((res) => { | ||
expect(res).to.exist | ||
expect(res.Keys).to.be.empty | ||
}) | ||
}) | ||
}) | ||
}) | ||
callback(null, fc) | ||
}, | ||
teardown: function (callback) { | ||
fc.dismantle(callback) | ||
} | ||
} | ||
|
||
test.pin(common) |