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

Commit 98bdff2

Browse files
committed
chore: fix up block.rm tests
1 parent cf3ef7b commit 98bdff2

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

src/block/rm.js

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,32 @@ module.exports = (createCommon, options) => {
3030
after((done) => common.teardown(done))
3131

3232
it('should remove by CID object', async () => {
33-
const cid = await ipfs.dag.put(Buffer.from(hat()))
33+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
34+
format: 'raw',
35+
hashAlg: 'sha2-256'
36+
})
3437

3538
// block should be present in the local store
36-
expect(await ipfs.refs.local()).to.deep.include({
37-
ref: cid.toString(),
38-
err: ''
39-
})
39+
const localRefs = await ipfs.refs.local()
40+
expect(localRefs).to.have.property('length').that.is.greaterThan(0)
41+
expect(localRefs.find(ref => ref.ref === cid.toString())).to.be.ok()
4042

4143
const result = await ipfs.block.rm(cid)
42-
4344
expect(result).to.be.an('array').and.to.have.lengthOf(1)
4445
expect(result[0]).to.have.property('hash', cid.toString())
4546
expect(result[0]).to.not.have.property('error')
4647

4748
// did we actually remove the block?
48-
expect(await ipfs.refs.local()).to.not.deep.include({
49-
ref: cid.toString(),
50-
err: ''
51-
})
49+
const localRefsAfterRemove = await ipfs.refs.local()
50+
expect(localRefsAfterRemove).to.have.property('length').that.is.greaterThan(0)
51+
expect(localRefsAfterRemove.find(ref => ref.ref === cid.toString())).to.not.be.ok()
5252
})
5353

5454
it('should remove by CID in string', async () => {
55-
const cid = await ipfs.dag.put(Buffer.from(hat()))
55+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
56+
format: 'raw',
57+
hashAlg: 'sha2-256'
58+
})
5659
const result = await ipfs.block.rm(cid.toString())
5760

5861
expect(result).to.be.an('array').and.to.have.lengthOf(1)
@@ -61,7 +64,10 @@ module.exports = (createCommon, options) => {
6164
})
6265

6366
it('should remove by CID in buffer', async () => {
64-
const cid = await ipfs.dag.put(Buffer.from(hat()))
67+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
68+
format: 'raw',
69+
hashAlg: 'sha2-256'
70+
})
6571
const result = await ipfs.block.rm(cid.buffer)
6672

6773
expect(result).to.be.an('array').and.to.have.lengthOf(1)
@@ -71,9 +77,18 @@ module.exports = (createCommon, options) => {
7177

7278
it('should remove multiple CIDs', async () => {
7379
const cids = [
74-
await ipfs.dag.put(Buffer.from(hat())),
75-
await ipfs.dag.put(Buffer.from(hat())),
76-
await ipfs.dag.put(Buffer.from(hat()))
80+
await ipfs.dag.put(Buffer.from(hat()), {
81+
format: 'raw',
82+
hashAlg: 'sha2-256'
83+
}),
84+
await ipfs.dag.put(Buffer.from(hat()), {
85+
format: 'raw',
86+
hashAlg: 'sha2-256'
87+
}),
88+
await ipfs.dag.put(Buffer.from(hat()), {
89+
format: 'raw',
90+
hashAlg: 'sha2-256'
91+
})
7792
]
7893

7994
const result = await ipfs.block.rm(cids)
@@ -87,7 +102,10 @@ module.exports = (createCommon, options) => {
87102
})
88103

89104
it('should error when removing non-existent blocks', async () => {
90-
const cid = await ipfs.dag.put(Buffer.from(hat()))
105+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
106+
format: 'raw',
107+
hashAlg: 'sha2-256'
108+
})
91109

92110
// remove it
93111
await ipfs.block.rm(cid)
@@ -100,7 +118,10 @@ module.exports = (createCommon, options) => {
100118
})
101119

102120
it('should not error when force removing non-existent blocks', async () => {
103-
const cid = await ipfs.dag.put(Buffer.from(hat()))
121+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
122+
format: 'raw',
123+
hashAlg: 'sha2-256'
124+
})
104125

105126
// remove it
106127
await ipfs.block.rm(cid)
@@ -114,10 +135,26 @@ module.exports = (createCommon, options) => {
114135
})
115136

116137
it('should return empty output when removing blocks quietly', async () => {
117-
const cid = await ipfs.dag.put(Buffer.from(hat()))
138+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
139+
format: 'raw',
140+
hashAlg: 'sha2-256'
141+
})
118142
const result = await ipfs.block.rm(cid, { quiet: true })
119143

120144
expect(result).to.be.an('array').and.to.have.lengthOf(0)
121145
})
146+
147+
it('should error when removing pinned blocks', async () => {
148+
const cid = await ipfs.dag.put(Buffer.from(hat()), {
149+
format: 'raw',
150+
hashAlg: 'sha2-256'
151+
})
152+
await ipfs.pin.add(cid.toString())
153+
154+
const result = await ipfs.block.rm(cid)
155+
156+
expect(result).to.be.an('array').and.to.have.lengthOf(1)
157+
expect(result[0]).to.have.property('error').and.to.include('pinned')
158+
})
122159
})
123160
}

0 commit comments

Comments
 (0)