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

Commit 04036eb

Browse files
committed
fix: add test for block rm
1 parent 41cf3a5 commit 04036eb

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

js/src/block/index.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const CID = require('cids')
5+
const auto = require('async/auto')
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('.block.rm', function () {
14+
const data = Buffer.from('blorb')
15+
let ipfs, hash
16+
17+
before(function (done) {
18+
// CI takes longer to instantiate the daemon, so we need to increase the
19+
// timeout for the before step
20+
this.timeout(60 * 1000)
21+
22+
auto({
23+
factory: (cb) => common.setup(cb),
24+
ipfs: ['factory', (res, cb) => res.factory.spawnNode(cb)],
25+
block: ['ipfs', (res, cb) => res.ipfs.block.put(data, cb)]
26+
}, (err, res) => {
27+
if (err) return done(err)
28+
ipfs = res.ipfs
29+
hash = res.block.cid.multihash
30+
done()
31+
})
32+
})
33+
34+
after((done) => common.teardown(done))
35+
36+
it('should remove by CID object', (done) => {
37+
const cid = new CID(hash)
38+
ipfs.block.rm(cid, (err) => {
39+
expect(err).to.not.exist()
40+
done()
41+
})
42+
})
43+
44+
it('should error on removing non-existent block', (done) => {
45+
const cid = new CID('QmYi5NFboBxXvdoRDSa7LaLcQvCukULCaDbZKXUXz4umPa')
46+
ipfs.block.rm(cid, (err, block) => {
47+
expect(err).to.exist()
48+
done()
49+
})
50+
})
51+
52+
// TODO it.skip('Promises support', (done) => {})
53+
})
54+
}

0 commit comments

Comments
 (0)