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

fix: add test for block rm #367

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/src/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { createSuite } = require('../utils/suite')
const tests = {
put: require('./put'),
get: require('./get'),
rm: require('./rm'),
stat: require('./stat')
}

Expand Down
54 changes: 54 additions & 0 deletions js/src/block/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-env mocha */
'use strict'

const CID = require('cids')
const auto = require('async/auto')
const { getDescribe, getIt, expect } = require('../utils/mocha')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.block.rm', function () {
const data = Buffer.from('blorb')
let ipfs, hash

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

auto({
factory: (cb) => common.setup(cb),
ipfs: ['factory', (res, cb) => res.factory.spawnNode(cb)],
block: ['ipfs', (res, cb) => res.ipfs.block.put(data, cb)]
}, (err, res) => {
if (err) return done(err)
ipfs = res.ipfs
hash = res.block.cid.multihash
done()
})
})

after((done) => common.teardown(done))

it('should remove by CID object', (done) => {
const cid = new CID(hash)
ipfs.block.rm(cid, (err) => {
expect(err).to.not.exist()
done()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure the block was removed, but I'm not sure if we have any public API for checking if a block already exists locally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
})

it('should error on removing non-existent block', (done) => {
const cid = new CID('QmYi5NFboBxXvdoRDSa7LaLcQvCukULCaDbZKXUXz4umPa')
ipfs.block.rm(cid, (err, block) => {
expect(err).to.exist()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure the error message contains whatever we expect it to have inside of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

done()
})
})

// TODO it.skip('Promises support', (done) => {})
})
}