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

Commit 51c346d

Browse files
committed
fix: add test for block rm
1 parent 41cf3a5 commit 51c346d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

js/src/block/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { createSuite } = require('../utils/suite')
44
const tests = {
55
put: require('./put'),
66
get: require('./get'),
7+
rm: require('./rm'),
78
stat: require('./stat')
89
}
910

js/src/block/rm.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)