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
157 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const bl = require('bl') | ||
const bs58 = require('bs58') | ||
const Readable = require('readable-stream') | ||
|
||
module.exports = (common) => { | ||
describe('.file', () => { | ||
let ipfs | ||
|
||
before((done) => { | ||
common.setup((err, _ipfs) => { | ||
expect(err).to.not.exist | ||
ipfs = _ipfs | ||
done() | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(done) | ||
}) | ||
|
||
// go-ipfs http and js-ipfs core have different responses | ||
describe('.add', () => { | ||
it('add', (done) => { | ||
const buffered = new Buffer('some data') | ||
const rs = new Readable() | ||
rs.push(buffered) | ||
rs.push(null) | ||
const arr = [] | ||
const filePair = {path: 'data.txt', content: rs} | ||
arr.push(filePair) | ||
ipfs.add(arr, (err, res) => { | ||
expect(err).to.not.exist | ||
expect(res[0].path).to.equal('data.txt') | ||
expect(res[0].size).to.equal(17) | ||
expect(bs58.encode(res[0].multihash).toString()).to.equal('QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.cat', () => { | ||
it('returns file stream', (done) => { | ||
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' | ||
ipfs.cat(hash, (err, file) => { | ||
expect(err).to.not.exist | ||
file.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
expect(bldata.toString()).to.contain('Check out some of the other files in this directory:') | ||
done() | ||
})) | ||
}) | ||
}) | ||
|
||
// This fails on js-ipfs-api | ||
it.skip('takes a buffer input', (done) => { | ||
const mhBuf = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')) | ||
ipfs.cat(mhBuf, (err, file) => { | ||
expect(err).to.not.exist | ||
file.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
expect(bldata.toString()).to.contain('Check out some of the other files in this directory:') | ||
done() | ||
})) | ||
}) | ||
}) | ||
|
||
// You can add a large file to your ipfs repo and change the hash to the file after installing js-ipfs | ||
it.skip('returns a large file', (done) => { | ||
const hash = '' | ||
ipfs.cat(hash, (err, file) => { | ||
expect(err).to.not.exist | ||
file.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
done() | ||
})) | ||
}) | ||
}) | ||
|
||
it('returns error on invalid key', (done) => { | ||
const hash = 'somethingNotMultihash' | ||
ipfs.cat(hash, (err, file) => { | ||
expect(err).to.exist | ||
const errString = err.toString() | ||
if (errString === 'Error: invalid ipfs ref path') { | ||
expect(err.toString()).to.contain('Error: invalid ipfs ref path') | ||
} | ||
if (errString === 'Error: Invalid Key') { | ||
expect(err.toString()).to.contain('Error: Invalid Key') | ||
} | ||
done() | ||
}) | ||
}) | ||
|
||
describe('promise', () => { | ||
it('files.cat', (done) => { | ||
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' | ||
ipfs.cat(hash) | ||
.then((stream) => { | ||
stream.pipe(bl((err, bldata) => { | ||
expect(err).to.not.exist | ||
expect(bldata.toString()).to.contain('Check out some of the other files in this directory:') | ||
done() | ||
})) | ||
}) | ||
.catch((err) => { | ||
expect(err).to.not.exist | ||
}) | ||
}) | ||
|
||
it('returns error on invalid key', (done) => { | ||
const hash = 'somethingNotMultihash' | ||
ipfs.cat(hash) | ||
.then((stream) => {}) | ||
.catch((err) => { | ||
expect(err).to.exist | ||
const errString = err.toString() | ||
if (errString === 'Error: invalid ipfs ref path') { | ||
expect(err.toString()).to.contain('Error: invalid ipfs ref path') | ||
} | ||
if (errString === 'Error: Invalid Key') { | ||
expect(err.toString()).to.contain('Error: Invalid Key') | ||
} | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
exports.all = () => {} | ||
exports.object = require('./object') | ||
exports.files = require('./files') |
Binary file not shown.