|
| 1 | +/* eslint max-nested-callbacks: ["error", 8] */ |
| 2 | +/* eslint-env mocha */ |
| 3 | +'use strict' |
| 4 | + |
| 5 | +const chai = require('chai') |
| 6 | +const dirtyChai = require('dirty-chai') |
| 7 | +const expect = chai.expect |
| 8 | +chai.use(dirtyChai) |
| 9 | + |
| 10 | +const IPFSFactory = require('ipfsd-ctl') |
| 11 | +const IPFS = require('../../src/core') |
| 12 | + |
| 13 | +describe('resolve', () => { |
| 14 | + let ipfsd, ipfs |
| 15 | + |
| 16 | + before(function (done) { |
| 17 | + this.timeout(20 * 1000) |
| 18 | + |
| 19 | + const factory = IPFSFactory.create({ type: 'proc' }) |
| 20 | + |
| 21 | + factory.spawn({ |
| 22 | + exec: IPFS, |
| 23 | + initOptions: { bits: 512 }, |
| 24 | + config: { Bootstrap: [] } |
| 25 | + }, (err, _ipfsd) => { |
| 26 | + expect(err).to.not.exist() |
| 27 | + ipfsd = _ipfsd |
| 28 | + ipfs = _ipfsd.api |
| 29 | + done() |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + after((done) => { |
| 34 | + if (ipfsd) { |
| 35 | + ipfsd.stop(done) |
| 36 | + } else { |
| 37 | + done() |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + it('should resolve an IPFS path non-link', (done) => { |
| 42 | + const content = { path: { to: { file: 'foobar' } } } |
| 43 | + const options = { format: 'dag-cbor', hashAlg: 'sha2-256' } |
| 44 | + |
| 45 | + ipfs.dag.put(content, options, (err, cid) => { |
| 46 | + expect(err).to.not.exist() |
| 47 | + |
| 48 | + // FIXME: This should be /ipld/... but that's not supported yet. |
| 49 | + const path = `/ipfs/${cid.toBaseEncodedString()}/path/to/file` |
| 50 | + ipfs.resolve(path, (err, resolved) => { |
| 51 | + expect(err).to.not.exist() |
| 52 | + expect(resolved).to.equal(path) |
| 53 | + done() |
| 54 | + }) |
| 55 | + }) |
| 56 | + }) |
| 57 | +}) |
0 commit comments