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

add tests for refs endpoint #460

Merged
merged 9 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion src/files-regular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const tests = {
getPullStream: require('./get-pull-stream'),
ls: require('./ls'),
lsReadableStream: require('./ls-readable-stream'),
lsPullStream: require('./ls-pull-stream')
lsPullStream: require('./ls-pull-stream'),
refs: require('./refs'),
refsReadableStream: require('./refs-readable-stream'),
refsPullStream: require('./refs-pull-stream'),
refsLocal: require('./refs-local'),
refsLocalPullStream: require('./refs-local-pull-stream'),
refsLocalReadableStream: require('./refs-local-readable-stream')
}

module.exports = createSuite(tests)
14 changes: 14 additions & 0 deletions src/files-regular/refs-local-pull-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env mocha */
'use strict'

const pull = require('pull-stream')

module.exports = (createCommon, options) => {
const ipfsRefsLocal = (ipfs) => {
return (cb) => {
const stream = ipfs.refs.localPullStream()
pull(stream, pull.collect(cb))
}
}
require('./refs-local-tests')(createCommon, '.refs.localPullStream', ipfsRefsLocal, options)
}
15 changes: 15 additions & 0 deletions src/files-regular/refs-local-readable-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env mocha */
'use strict'

const concat = require('concat-stream')

module.exports = (createCommon, options) => {
const ipfsRefsLocal = (ipfs) => {
return (cb) => {
const stream = ipfs.refs.localReadableStream()
stream.on('error', cb)
stream.pipe(concat((refs) => cb(null, refs)))
}
}
require('./refs-local-tests')(createCommon, '.refs.localReadableStream', ipfsRefsLocal, options)
}
60 changes: 60 additions & 0 deletions src/files-regular/refs-local-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-env mocha */
'use strict'

const { fixtures } = require('./utils')
const { getDescribe, getIt, expect } = require('../utils/mocha')

module.exports = (createCommon, suiteName, ipfsRefsLocal, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe(suiteName, 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 get local refs', function (done) {
const content = (name) => ({
path: `test-folder/${name}`,
content: fixtures.directory.files[name]
})

const dirs = [
content('pp.txt'),
content('holmes.txt')
]

ipfs.add(dirs, (err, res) => {
expect(err).to.not.exist()

ipfsRefsLocal(ipfs)((err, refs) => {
expect(err).to.not.exist()

const cids = refs.map(r => r.Ref)
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
expect(cids.includes('QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn')).to.eql(true)
expect(cids.includes('QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr')).to.eql(true)
dirkmc marked this conversation as resolved.
Show resolved Hide resolved

done()
})
})
})
})
}
7 changes: 7 additions & 0 deletions src/files-regular/refs-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env mocha */
'use strict'

module.exports = (createCommon, options) => {
const ipfsRefsLocal = (ipfs) => (cb) => ipfs.refs.local(cb)
require('./refs-local-tests')(createCommon, '.refs.local', ipfsRefsLocal, options)
}
14 changes: 14 additions & 0 deletions src/files-regular/refs-pull-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env mocha */
'use strict'

const pull = require('pull-stream')

module.exports = (createCommon, options) => {
const ipfsRefs = (ipfs) => {
return (path, params, cb) => {
const stream = ipfs.refsPullStream(path, params)
pull(stream, pull.collect(cb))
}
}
require('./refs-tests')(createCommon, '.refsPullStream', ipfsRefs, options)
}
15 changes: 15 additions & 0 deletions src/files-regular/refs-readable-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env mocha */
'use strict'

const concat = require('concat-stream')

module.exports = (createCommon, options) => {
const ipfsRefs = (ipfs) => {
return (path, params, cb) => {
const stream = ipfs.refsReadableStream(path, params)
stream.on('error', cb)
stream.pipe(concat((refs) => cb(null, refs)))
}
}
require('./refs-tests')(createCommon, '.refsReadableStream', ipfsRefs, options)
}
Loading