|
| 1 | +/* eslint-env mocha */ |
| 2 | +/* eslint max-nested-callbacks: ["error", 6] */ |
| 3 | +'use strict' |
| 4 | + |
| 5 | +const { fixtures } = require('./utils') |
| 6 | +const { getDescribe, getIt, expect } = require('../utils/mocha') |
| 7 | + |
| 8 | +module.exports = (createCommon, options) => { |
| 9 | + const describe = getDescribe(options) |
| 10 | + const it = getIt(options) |
| 11 | + const common = createCommon() |
| 12 | + |
| 13 | + describe('.refs', function () { |
| 14 | + this.timeout(40 * 1000) |
| 15 | + |
| 16 | + let ipfs |
| 17 | + |
| 18 | + before(function (done) { |
| 19 | + // CI takes longer to instantiate the daemon, so we need to increase the |
| 20 | + // timeout for the before step |
| 21 | + this.timeout(60 * 1000) |
| 22 | + |
| 23 | + common.setup((err, factory) => { |
| 24 | + expect(err).to.not.exist() |
| 25 | + factory.spawnNode((err, node) => { |
| 26 | + expect(err).to.not.exist() |
| 27 | + ipfs = node |
| 28 | + done() |
| 29 | + }) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + after((done) => common.teardown(done)) |
| 34 | + |
| 35 | + it('refs', function (done) { |
| 36 | + module.exports.addTestFolder(ipfs, (err, cid) => { |
| 37 | + expect(err).to.not.exist() |
| 38 | + |
| 39 | + ipfs.refs(cid, { format: module.exports.expectedResults.format }, (err, refs) => { |
| 40 | + expect(err).to.not.exist() |
| 41 | + |
| 42 | + expect(refs.map(r => r.Ref)).to.eql(module.exports.expectedResults.results) |
| 43 | + done() |
| 44 | + }) |
| 45 | + }) |
| 46 | + }) |
| 47 | + }) |
| 48 | +} |
| 49 | + |
| 50 | +module.exports.expectedResults = { |
| 51 | + format: '<src> <dst> <linkname>', |
| 52 | + results: [ |
| 53 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi alice.txt', |
| 54 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn empty-folder', |
| 55 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74 files', |
| 56 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr holmes.txt', |
| 57 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9 jungle.txt', |
| 58 | + 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn pp.txt' |
| 59 | + ] |
| 60 | +} |
| 61 | + |
| 62 | +module.exports.addTestFolder = (ipfs, callback) => { |
| 63 | + const content = (name) => ({ |
| 64 | + path: `test-folder/${name}`, |
| 65 | + content: fixtures.directory.files[name] |
| 66 | + }) |
| 67 | + |
| 68 | + const emptyDir = (name) => ({ path: `test-folder/${name}` }) |
| 69 | + |
| 70 | + const dirs = [ |
| 71 | + content('pp.txt'), |
| 72 | + content('holmes.txt'), |
| 73 | + content('jungle.txt'), |
| 74 | + content('alice.txt'), |
| 75 | + emptyDir('empty-folder'), |
| 76 | + content('files/hello.txt'), |
| 77 | + content('files/ipfs.txt'), |
| 78 | + emptyDir('files/empty') |
| 79 | + ] |
| 80 | + |
| 81 | + ipfs.add(dirs, (err, res) => { |
| 82 | + expect(err).to.not.exist() |
| 83 | + const root = res[res.length - 1] |
| 84 | + |
| 85 | + expect(root.path).to.equal('test-folder') |
| 86 | + expect(root.hash).to.equal(fixtures.directory.cid) |
| 87 | + |
| 88 | + const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' |
| 89 | + |
| 90 | + callback(null, cid) |
| 91 | + }) |
| 92 | +} |
0 commit comments