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

Commit b791922

Browse files
committed
feat: additional tests for indirect pin.ls
License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent e8955b1 commit b791922

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

src/pin/ls.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,18 @@ module.exports = (createCommon, options) => {
3131

3232
function populate () {
3333
series([
34-
cb => { // two files wrapped in a directory, root CID pinned recursively
34+
// two files wrapped in directories, only root CID pinned recursively
35+
cb => {
3536
const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data }))
36-
ipfs.files.add(dir, { pin: false }, (err, res) => {
37-
if (err) return cb(err)
38-
ipfs.pin.add(fixtures.directory.cid, { recursive: true }, cb)
39-
})
37+
ipfs.add(dir, { pin: false, cidVersion: 0 }, cb)
4038
},
41-
cb => { // a file (CID pinned recursively)
42-
ipfs.files.add(fixtures.files[0].data, { pin: false }, (err, res) => {
43-
if (err) return cb(err)
44-
ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb)
45-
})
46-
},
47-
cb => { // a single CID (pinned directly)
48-
ipfs.files.add(fixtures.files[1].data, { pin: false }, (err, res) => {
49-
if (err) return cb(err)
50-
ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
51-
})
52-
}
39+
cb => ipfs.pin.add(fixtures.directory.cid, { recursive: true }, cb),
40+
// a file (CID pinned recursively)
41+
cb => ipfs.add(fixtures.files[0].data, { pin: false, cidVersion: 0 }, cb),
42+
cb => ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb),
43+
// a single CID (pinned directly)
44+
cb => ipfs.add(fixtures.files[1].data, { pin: false, cidVersion: 0 }, cb),
45+
cb => ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
5346
], done)
5447
}
5548
})
@@ -87,6 +80,14 @@ module.exports = (createCommon, options) => {
8780
type: 'recursive',
8881
hash: fixtures.directory.cid
8982
})
83+
expect(pinset).to.deep.include({
84+
type: 'indirect',
85+
hash: fixtures.directory.files[0].cid
86+
})
87+
expect(pinset).to.deep.include({
88+
type: 'indirect',
89+
hash: fixtures.directory.files[1].cid
90+
})
9091
done()
9192
})
9293
})
@@ -95,7 +96,6 @@ module.exports = (createCommon, options) => {
9596
ipfs.pin.ls((err, pinset) => {
9697
expect(err).to.not.exist()
9798
expect(pinset).to.not.be.empty()
98-
expect(pinset).to.have.lengthOf(15)
9999
// check the three "roots"
100100
expect(pinset).to.deep.include({
101101
type: 'recursive',
@@ -109,6 +109,14 @@ module.exports = (createCommon, options) => {
109109
type: 'direct',
110110
hash: fixtures.files[1].cid
111111
})
112+
expect(pinset).to.deep.include({
113+
type: 'indirect',
114+
hash: fixtures.directory.files[0].cid
115+
})
116+
expect(pinset).to.deep.include({
117+
type: 'indirect',
118+
hash: fixtures.directory.files[1].cid
119+
})
112120
done()
113121
})
114122
})
@@ -117,7 +125,6 @@ module.exports = (createCommon, options) => {
117125
return ipfs.pin.ls()
118126
.then((pinset) => {
119127
expect(pinset).to.not.be.empty()
120-
expect(pinset).to.have.lengthOf(15)
121128
// check our three "roots"
122129
expect(pinset).to.deep.include({
123130
type: 'recursive',
@@ -131,12 +138,21 @@ module.exports = (createCommon, options) => {
131138
type: 'direct',
132139
hash: fixtures.files[1].cid
133140
})
141+
expect(pinset).to.deep.include({
142+
type: 'indirect',
143+
hash: fixtures.directory.files[0].cid
144+
})
145+
expect(pinset).to.deep.include({
146+
type: 'indirect',
147+
hash: fixtures.directory.files[1].cid
148+
})
134149
})
135150
})
136151

137152
it('should list all direct pins', (done) => {
138153
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
139154
expect(err).to.not.exist()
155+
expect(pinset).to.have.lengthOf(1)
140156
expect(pinset).to.deep.include({
141157
type: 'direct',
142158
hash: fixtures.files[1].cid
@@ -166,21 +182,21 @@ module.exports = (createCommon, options) => {
166182
})
167183
})
168184

169-
it('should throw an error on missing direct pins for a specific path', (done) => {
170-
// alice.txt is an indirect pin, so lookup for direct one should throw an error
185+
it('should throw an error on missing direct pins for existing path', (done) => {
186+
// ipfs.txt is an indirect pin, so lookup for direct one should throw an error
171187
ipfs.pin.ls(`/ipfs/${fixtures.directory.cid}/files/ipfs.txt`, { type: 'direct' }, (err, pinset) => {
188+
expect(err).to.exist()
172189
expect(pinset).to.not.exist()
173-
expect(err).to.not.be.empty()
174190
expect(err.message).to.be.equal(`path '/ipfs/${fixtures.directory.cid}/files/ipfs.txt' is not pinned`)
175191
done()
176192
})
177193
})
178194

179195
it('should throw an error on missing link for a specific path', (done) => {
180196
ipfs.pin.ls(`/ipfs/${fixtures.directory.cid}/I-DONT-EXIST.txt`, { type: 'direct' }, (err, pinset) => {
197+
expect(err).to.exist()
181198
expect(pinset).to.not.exist()
182-
expect(err).to.not.be.empty()
183-
expect(err.message).to.be.equal('no link by that name')
199+
expect(err.message).to.be.equal(`no link named "I-DONT-EXIST.txt" under ${fixtures.directory.cid}`)
184200
done()
185201
})
186202
})

src/pin/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
const loadFixture = require('aegir/fixtures')
44

55
exports.fixtures = Object.freeze({
6+
// NOTE: files under 'directory' need to be different than standalone ones in 'files'
67
directory: Object.freeze({
7-
cid: 'QmVJV2VF9Qf7rJUFdimhpZDhkyyumM1i4CjjGcss5rqJPa',
8+
cid: 'QmY8KdYQSYKFU5hM7F5ioZ5yYSgV5VZ1kDEdqfRL3rFgcd',
89
files: Object.freeze([Object.freeze({
910
path: 'test-folder/ipfs-add.js',
10-
data: loadFixture('js/test/fixtures/test-folder/ipfs-add.js', 'interface-ipfs-core'),
11-
cid: 'QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL'
11+
data: loadFixture('test/fixtures/test-folder/ipfs-add.js', 'interface-ipfs-core'),
12+
cid: 'QmbKtKBrmeRHjNCwR4zAfCJdMVu6dgmwk9M9AE9pUM9RgG'
1213
}), Object.freeze({
1314
path: 'test-folder/files/ipfs.txt',
14-
data: loadFixture('js/test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core'),
15+
data: loadFixture('test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core'),
1516
cid: 'QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w'
1617
})])
1718
}),

0 commit comments

Comments
 (0)