This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathadd-all.js
128 lines (111 loc) · 2.97 KB
/
add-all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* eslint-env mocha */
import { fixtures, clearPins } from './utils.js'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import all from 'it-all'
import drain from 'it-drain'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testAddAll (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.pin.addAll', function () {
this.timeout(50 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
await drain(
ipfs.addAll(
fixtures.files.map(file => ({ content: file.data })), {
pin: false
}
)
)
await drain(
ipfs.addAll(fixtures.directory.files.map(
file => ({
path: file.path,
content: file.data
})
), {
pin: false
})
)
})
after(() => factory.clean())
beforeEach(() => {
return clearPins(ipfs)
})
/**
*
* @param {Iterable<import('ipfs-core-types/src/pin').AddInput> | AsyncIterable<import('ipfs-core-types/src/pin').AddInput>} source
*/
async function testAddPinInput (source) {
const pinset = await all(ipfs.pin.addAll(source))
expect(pinset).to.have.deep.members([
fixtures.files[0].cid,
fixtures.files[1].cid
])
}
it('should add an array of CIDs', () => {
return testAddPinInput([
fixtures.files[0].cid,
fixtures.files[1].cid
])
})
it('should add a generator of CIDs', () => {
return testAddPinInput(function * () {
yield fixtures.files[0].cid
yield fixtures.files[1].cid
}())
})
it('should add an async generator of CIDs', () => {
return testAddPinInput(async function * () { // eslint-disable-line require-await
yield fixtures.files[0].cid
yield fixtures.files[1].cid
}())
})
it('should add an array of pins with options', () => {
return testAddPinInput([
{
cid: fixtures.files[0].cid,
recursive: false
},
{
cid: fixtures.files[1].cid,
recursive: true
}
])
})
it('should add a generator of pins with options', () => {
return testAddPinInput(function * () {
yield {
cid: fixtures.files[0].cid,
recursive: false
}
yield {
cid: fixtures.files[1].cid,
recursive: true
}
}())
})
it('should add an async generator of pins with options', () => {
return testAddPinInput(async function * () { // eslint-disable-line require-await
yield {
cid: fixtures.files[0].cid,
recursive: false
}
yield {
cid: fixtures.files[1].cid,
recursive: true
}
}())
})
})
}