|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const multihash = require('multihashes') |
| 5 | +const CID = require('cids') |
| 6 | +const auto = require('async/auto') |
| 7 | +const { getDescribe, getIt, expect } = require('../utils/mocha') |
| 8 | + |
| 9 | +module.exports = (createCommon, options) => { |
| 10 | + const describe = getDescribe(options) |
| 11 | + const it = getIt(options) |
| 12 | + const common = createCommon() |
| 13 | + |
| 14 | + describe('.block.rm', function () { |
| 15 | + const data = Buffer.from('blorb') |
| 16 | + let ipfs, hash |
| 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 | + auto({ |
| 24 | + factory: (cb) => common.setup(cb), |
| 25 | + ipfs: ['factory', (res, cb) => res.factory.spawnNode(cb)], |
| 26 | + block: ['ipfs', (res, cb) => res.ipfs.block.put(data, cb)] |
| 27 | + }, (err, res) => { |
| 28 | + if (err) return done(err) |
| 29 | + ipfs = res.ipfs |
| 30 | + hash = res.block.cid.multihash |
| 31 | + done() |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + after((done) => common.teardown(done)) |
| 36 | + |
| 37 | + it('should remove by CID object', (done) => { |
| 38 | + const cid = new CID(hash) |
| 39 | + ipfs.block.rm(cid, (err) => { |
| 40 | + console.log('vmx: error:', err) |
| 41 | + expect(err).to.not.exist() |
| 42 | + done() |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should error on removing non-existent block', (done) => { |
| 47 | + const cid = new CID('QmYi5NFboBxXvdoRDSa7LaLcQvCukULCaDbZKXUXz4umPa') |
| 48 | + ipfs.block.rm(cid, (err, block) => { |
| 49 | + expect(err).to.exist() |
| 50 | + done() |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + // TODO it.skip('Promises support', (done) => {}) |
| 55 | + }) |
| 56 | +} |
0 commit comments