This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
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
4 changed files
with
155 additions
and
11 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 |
---|---|---|
|
@@ -47,4 +47,4 @@ | |
"greenkeeperio-bot <[email protected]>", | ||
"nginnever <[email protected]>" | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const testfile = fs.readFileSync(path.join(__dirname, './data/testfile.txt')) | ||
|
||
module.exports = (common) => { | ||
describe('.pin', () => { | ||
let ipfs | ||
|
||
before(function (done) { | ||
// CI is slow | ||
this.timeout(20 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(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() | ||
}) | ||
}) | ||
|
||
describe('callback API', () => { | ||
it('.rm (1st, because ipfs.files.add pins automatically)', (done) => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
ipfs.pin.rm(hash, { recursive: true }, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
ipfs.pin.ls({ type: 'direct' }, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
expect(res.Keys).to.be.empty | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('.add', (done) => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
ipfs.pin.add(hash, { recursive: false }, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res.Pins[0]).to.be.equal(hash) | ||
done() | ||
}) | ||
}) | ||
|
||
it('.list', (done) => { | ||
ipfs.pin.ls((err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
done() | ||
}) | ||
}) | ||
|
||
it('.list for a specific hash', (done) => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
ipfs.pin.ls(hash, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.exist | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('promise API', () => { | ||
it('.add', () => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
return ipfs.pin.add(hash, { recursive: false }) | ||
.then((res) => { | ||
expect(res.Pins[0]).to.be.equal(hash) | ||
}) | ||
}) | ||
|
||
it('.ls', () => { | ||
return ipfs.pin.ls() | ||
.then((res) => { | ||
expect(res).to.exist | ||
}) | ||
}) | ||
|
||
it('.ls hash', () => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
return ipfs.pin.ls(hash) | ||
.then((res) => { | ||
expect(res).to.exist | ||
}) | ||
}) | ||
|
||
it('.rm', () => { | ||
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
|
||
return ipfs.pin.rm(hash, { recursive: false }) | ||
.then((res) => { | ||
expect(res).to.exist | ||
return ipfs.pin.ls({ type: 'direct' }) | ||
}) | ||
.then((res) => { | ||
expect(res).to.exist | ||
expect(res.Keys).to.be.empty | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |