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
3 changed files
with
148 additions
and
1 deletion.
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,53 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 6] */ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
const { expectedResults, addTestFolder } = require('./refs') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.refsPullStream', function () { | ||
this.timeout(40 * 1000) | ||
|
||
let ipfs | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 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('should pull stream refs', function (done) { | ||
addTestFolder(ipfs, (err, cid) => { | ||
expect(err).to.not.exist() | ||
|
||
const stream = ipfs.refsPullStream(cid, { format: expectedResults.format }) | ||
pull( | ||
stream, | ||
pull.collect((err, refs) => { | ||
expect(err).to.not.exist() | ||
|
||
expect(refs.map(r => r.Ref)).to.eql(expectedResults.results) | ||
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 6] */ | ||
'use strict' | ||
|
||
const { fixtures } = require('./utils') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.refs', function () { | ||
this.timeout(40 * 1000) | ||
|
||
let ipfs | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 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('refs', function (done) { | ||
module.exports.addTestFolder(ipfs, (err, cid) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs.refs(cid, { format: module.exports.expectedResults.format }, (err, refs) => { | ||
expect(err).to.not.exist() | ||
|
||
expect(refs.map(r => r.Ref)).to.eql(module.exports.expectedResults.results) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports.expectedResults = { | ||
format: '<src> <dst> <linkname>', | ||
results: [ | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi alice.txt', | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn empty-folder', | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74 files', | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr holmes.txt', | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9 jungle.txt', | ||
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn pp.txt' | ||
] | ||
} | ||
|
||
module.exports.addTestFolder = (ipfs, callback) => { | ||
const content = (name) => ({ | ||
path: `test-folder/${name}`, | ||
content: fixtures.directory.files[name] | ||
}) | ||
|
||
const emptyDir = (name) => ({ path: `test-folder/${name}` }) | ||
|
||
const dirs = [ | ||
content('pp.txt'), | ||
content('holmes.txt'), | ||
content('jungle.txt'), | ||
content('alice.txt'), | ||
emptyDir('empty-folder'), | ||
content('files/hello.txt'), | ||
content('files/ipfs.txt'), | ||
emptyDir('files/empty') | ||
] | ||
|
||
ipfs.add(dirs, (err, res) => { | ||
expect(err).to.not.exist() | ||
const root = res[res.length - 1] | ||
|
||
expect(root.path).to.equal('test-folder') | ||
expect(root.hash).to.equal(fixtures.directory.cid) | ||
|
||
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' | ||
|
||
callback(null, cid) | ||
}) | ||
} |