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

Commit ae74cbc

Browse files
committed
feat: refactor all the tests to match new files API
1 parent 98127f8 commit ae74cbc

28 files changed

+110
-119
lines changed

js/src/dht/provide.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = (createCommon, options) => {
3535
after((done) => common.teardown(done))
3636

3737
it('should provide local CID', (done) => {
38-
ipfs.files.add(Buffer.from('test'), (err, res) => {
38+
ipfs.add(Buffer.from('test'), (err, res) => {
3939
if (err) return done(err)
4040

4141
ipfs.dht.provide(new CID(res[0].hash), (err) => {
@@ -56,7 +56,7 @@ module.exports = (createCommon, options) => {
5656
})
5757

5858
it('should allow multiple CIDs to be passed', (done) => {
59-
ipfs.files.add([Buffer.from('t0'), Buffer.from('t1')], (err, res) => {
59+
ipfs.add([Buffer.from('t0'), Buffer.from('t1')], (err, res) => {
6060
if (err) return done(err)
6161

6262
ipfs.dht.provide([
@@ -70,7 +70,7 @@ module.exports = (createCommon, options) => {
7070
})
7171

7272
it('should provide a CIDv1', (done) => {
73-
ipfs.files.add(Buffer.from('test'), { 'cid-version': 1 }, (err, res) => {
73+
ipfs.add(Buffer.from('test'), { 'cid-version': 1 }, (err, res) => {
7474
if (err) return done(err)
7575

7676
const cid = new CID(res[0].hash)

js/src/files-mfs/stat.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const series = require('async/series')
55
const hat = require('hat')
6-
const { fixtures } = require('./utils')
6+
const { fixtures } = require('../files-regular/utils')
77
const { getDescribe, getIt, expect } = require('../utils/mocha')
88

99
module.exports = (createCommon, options) => {
@@ -31,7 +31,7 @@ module.exports = (createCommon, options) => {
3131
})
3232
})
3333

34-
before((done) => ipfs.files.add(fixtures.smallFile.data, done))
34+
before((done) => ipfs.add(fixtures.smallFile.data, done))
3535

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

@@ -98,7 +98,7 @@ module.exports = (createCommon, options) => {
9898

9999
// TODO enable this test when this feature gets released on go-ipfs
100100
it.skip('should stat withLocal file', function (done) {
101-
ipfs.files.stat('/test/b', {withLocal: true}, (err, stat) => {
101+
ipfs.files.stat('/test/b', { withLocal: true }, (err, stat) => {
102102
expect(err).to.not.exist()
103103
expect(stat).to.eql({
104104
type: 'file',
@@ -116,7 +116,7 @@ module.exports = (createCommon, options) => {
116116

117117
// TODO enable this test when this feature gets released on go-ipfs
118118
it.skip('should stat withLocal dir', function (done) {
119-
ipfs.files.stat('/test', {withLocal: true}, (err, stat) => {
119+
ipfs.files.stat('/test', { withLocal: true }, (err, stat) => {
120120
expect(err).to.not.exist()
121121
expect(stat).to.eql({
122122
type: 'directory',

js/src/files-regular/add-from-fs.js

Whitespace-only changes.

js/src/files-regular/add-from-url.js

Whitespace-only changes.

js/src/files-regular/add-pull-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.files.addPullStream', function () {
13+
describe('.addPullStream', function () {
1414
this.timeout(40 * 1000)
1515

1616
let ipfs
@@ -51,7 +51,7 @@ module.exports = (createCommon, options) => {
5151
emptyDir('files/empty')
5252
]
5353

54-
const stream = ipfs.files.addPullStream()
54+
const stream = ipfs.addPullStream()
5555

5656
pull(
5757
pull.values(files),
@@ -74,7 +74,7 @@ module.exports = (createCommon, options) => {
7474

7575
pull(
7676
pull.values([{ content: pull.values([Buffer.from('test')]) }]),
77-
ipfs.files.addPullStream(),
77+
ipfs.addPullStream(),
7878
pull.collect((err, res) => {
7979
if (err) return done(err)
8080
expect(res).to.have.length(1)

js/src/files-regular/add-readable-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.files.addReadableStream', function () {
12+
describe('.addReadableStream', function () {
1313
this.timeout(40 * 1000)
1414

1515
let ipfs
@@ -50,7 +50,7 @@ module.exports = (createCommon, options) => {
5050
emptyDir('files/empty')
5151
]
5252

53-
const stream = ipfs.files.addReadableStream()
53+
const stream = ipfs.addReadableStream()
5454

5555
stream.on('error', (err) => {
5656
expect(err).to.not.exist()

js/src/files-regular/add.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = (createCommon, options) => {
1313
const it = getIt(options)
1414
const common = createCommon()
1515

16-
describe('.files.add', function () {
16+
describe('.add', function () {
1717
this.timeout(40 * 1000)
1818

1919
let ipfs
@@ -36,7 +36,7 @@ module.exports = (createCommon, options) => {
3636
after((done) => common.teardown(done))
3737

3838
it('should add a Buffer', (done) => {
39-
ipfs.files.add(fixtures.smallFile.data, (err, filesAdded) => {
39+
ipfs.add(fixtures.smallFile.data, (err, filesAdded) => {
4040
expect(err).to.not.exist()
4141

4242
expect(filesAdded).to.have.length(1)
@@ -50,7 +50,7 @@ module.exports = (createCommon, options) => {
5050
})
5151

5252
it('should add a Buffer (promised)', () => {
53-
return ipfs.files.add(fixtures.smallFile.data)
53+
return ipfs.add(fixtures.smallFile.data)
5454
.then((filesAdded) => {
5555
const file = filesAdded[0]
5656
expect(file.hash).to.equal(fixtures.smallFile.cid)
@@ -59,7 +59,7 @@ module.exports = (createCommon, options) => {
5959
})
6060

6161
it('should add a BIG Buffer', (done) => {
62-
ipfs.files.add(fixtures.bigFile.data, (err, filesAdded) => {
62+
ipfs.add(fixtures.bigFile.data, (err, filesAdded) => {
6363
expect(err).to.not.exist()
6464

6565
expect(filesAdded).to.have.length(1)
@@ -80,7 +80,7 @@ module.exports = (createCommon, options) => {
8080
accumProgress = p
8181
}
8282

83-
ipfs.files.add(fixtures.bigFile.data, { progress: handler }, (err, filesAdded) => {
83+
ipfs.add(fixtures.bigFile.data, { progress: handler }, (err, filesAdded) => {
8484
expect(err).to.not.exist()
8585

8686
expect(filesAdded).to.have.length(1)
@@ -97,7 +97,7 @@ module.exports = (createCommon, options) => {
9797
it('should add a Buffer as tuple', (done) => {
9898
const tuple = { path: 'testfile.txt', content: fixtures.smallFile.data }
9999

100-
ipfs.files.add([
100+
ipfs.add([
101101
tuple
102102
], (err, filesAdded) => {
103103
expect(err).to.not.exist()
@@ -114,7 +114,7 @@ module.exports = (createCommon, options) => {
114114
it('should not be able to add by path', (done) => {
115115
const validPath = path.join(process.cwd() + '/package.json')
116116

117-
ipfs.files.add(validPath, (err, res) => {
117+
ipfs.add(validPath, (err, res) => {
118118
expect(err).to.exist()
119119
done()
120120
})
@@ -127,7 +127,7 @@ module.exports = (createCommon, options) => {
127127
rs.push(Buffer.from('some data'))
128128
rs.push(null)
129129

130-
ipfs.files.add(rs, (err, filesAdded) => {
130+
ipfs.add(rs, (err, filesAdded) => {
131131
expect(err).to.not.exist()
132132

133133
expect(filesAdded).to.be.length(1)
@@ -148,7 +148,7 @@ module.exports = (createCommon, options) => {
148148

149149
const tuple = { path: 'data.txt', content: rs }
150150

151-
ipfs.files.add([tuple], (err, filesAdded) => {
151+
ipfs.add([tuple], (err, filesAdded) => {
152152
expect(err).to.not.exist()
153153

154154
expect(filesAdded).to.be.length(1)
@@ -163,7 +163,7 @@ module.exports = (createCommon, options) => {
163163
it('should add pull stream', (done) => {
164164
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
165165

166-
ipfs.files.add(pull.values([Buffer.from('test')]), (err, res) => {
166+
ipfs.add(pull.values([Buffer.from('test')]), (err, res) => {
167167
if (err) return done(err)
168168
expect(res).to.have.length(1)
169169
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
@@ -174,7 +174,7 @@ module.exports = (createCommon, options) => {
174174
it('should add pull stream (promised)', () => {
175175
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
176176

177-
return ipfs.files.add(pull.values([Buffer.from('test')]))
177+
return ipfs.add(pull.values([Buffer.from('test')]))
178178
.then((res) => {
179179
expect(res).to.have.length(1)
180180
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
@@ -184,7 +184,7 @@ module.exports = (createCommon, options) => {
184184
it('should add array of objects with pull stream content (promised)', () => {
185185
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
186186

187-
return ipfs.files.add([{ content: pull.values([Buffer.from('test')]) }])
187+
return ipfs.add([{ content: pull.values([Buffer.from('test')]) }])
188188
.then((res) => {
189189
expect(res).to.have.length(1)
190190
expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 })
@@ -210,7 +210,7 @@ module.exports = (createCommon, options) => {
210210
emptyDir('files/empty')
211211
]
212212

213-
ipfs.files.add(dirs, (err, res) => {
213+
ipfs.add(dirs, (err, res) => {
214214
expect(err).to.not.exist()
215215
const root = res[res.length - 1]
216216

@@ -250,7 +250,7 @@ module.exports = (createCommon, options) => {
250250
accumProgress += p
251251
}
252252

253-
ipfs.files.add(dirs, { progress: handler }, (err, filesAdded) => {
253+
ipfs.add(dirs, { progress: handler }, (err, filesAdded) => {
254254
expect(err).to.not.exist()
255255
const root = filesAdded[filesAdded.length - 1]
256256

@@ -265,7 +265,7 @@ module.exports = (createCommon, options) => {
265265
it('should fail when passed invalid input', (done) => {
266266
const nonValid = 'sfdasfasfs'
267267

268-
ipfs.files.add(nonValid, (err, result) => {
268+
ipfs.add(nonValid, (err, result) => {
269269
expect(err).to.exist()
270270
done()
271271
})
@@ -274,7 +274,7 @@ module.exports = (createCommon, options) => {
274274
it('should wrap content in a directory', (done) => {
275275
const data = { path: 'testfile.txt', content: fixtures.smallFile.data }
276276

277-
ipfs.files.add(data, { wrapWithDirectory: true }, (err, filesAdded) => {
277+
ipfs.add(data, { wrapWithDirectory: true }, (err, filesAdded) => {
278278
expect(err).to.not.exist()
279279
expect(filesAdded).to.have.length(2)
280280
const file = filesAdded[0]
@@ -290,7 +290,7 @@ module.exports = (createCommon, options) => {
290290
this.slow(10 * 1000)
291291
const content = String(Math.random() + Date.now())
292292

293-
return ipfs.files.add(Buffer.from(content), { onlyHash: true })
293+
return ipfs.add(Buffer.from(content), { onlyHash: true })
294294
.then(files => {
295295
expect(files).to.have.length(1)
296296

js/src/files-regular/cat-pull-stream.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.files.catPullStream', function () {
13+
describe('.catPullStream', function () {
1414
this.timeout(40 * 1000)
1515

1616
let ipfs
@@ -30,12 +30,12 @@ module.exports = (createCommon, options) => {
3030
})
3131
})
3232

33-
before((done) => ipfs.files.add(fixtures.smallFile.data, done))
33+
before((done) => ipfs.add(fixtures.smallFile.data, done))
3434

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

3737
it('should return a Pull Stream for a CID', (done) => {
38-
const stream = ipfs.files.catPullStream(fixtures.smallFile.cid)
38+
const stream = ipfs.catPullStream(fixtures.smallFile.cid)
3939

4040
pull(
4141
stream,
@@ -52,7 +52,7 @@ module.exports = (createCommon, options) => {
5252
const offset = 1
5353
const length = 3
5454

55-
const stream = ipfs.files.catPullStream(fixtures.smallFile.cid, {
55+
const stream = ipfs.catPullStream(fixtures.smallFile.cid, {
5656
offset,
5757
length
5858
})

js/src/files-regular/cat-readable-stream.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.files.catReadableStream', function () {
13+
describe('.catReadableStream', function () {
1414
this.timeout(40 * 1000)
1515

1616
let ipfs
@@ -30,13 +30,13 @@ module.exports = (createCommon, options) => {
3030
})
3131
})
3232

33-
before((done) => ipfs.files.add(fixtures.bigFile.data, done))
34-
before((done) => ipfs.files.add(fixtures.smallFile.data, done))
33+
before((done) => ipfs.add(fixtures.bigFile.data, done))
34+
before((done) => ipfs.add(fixtures.smallFile.data, done))
3535

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

3838
it('should return a Readable Stream for a CID', (done) => {
39-
const stream = ipfs.files.catReadableStream(fixtures.bigFile.cid)
39+
const stream = ipfs.catReadableStream(fixtures.bigFile.cid)
4040

4141
stream.pipe(bl((err, data) => {
4242
expect(err).to.not.exist()
@@ -49,7 +49,7 @@ module.exports = (createCommon, options) => {
4949
const offset = 1
5050
const length = 3
5151

52-
const stream = ipfs.files.catReadableStream(fixtures.smallFile.cid, {
52+
const stream = ipfs.catReadableStream(fixtures.smallFile.cid, {
5353
offset,
5454
length
5555
})

0 commit comments

Comments
 (0)