This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move regular files api to top level, add addFromFs and addFromU…
…rl (#378)
- Loading branch information
Showing
62 changed files
with
14,461 additions
and
278 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const { createSuite } = require('../utils/suite') | ||
|
||
const tests = { | ||
mkdir: require('./mkdir'), | ||
write: require('./write'), | ||
cp: require('./cp'), | ||
mv: require('./mv'), | ||
rm: require('./rm'), | ||
stat: require('./stat'), | ||
read: require('./read'), | ||
readReadableStream: require('./read-readable-stream'), | ||
readPullStream: require('./read-pull-stream'), | ||
ls: require('./ls'), | ||
flush: require('./flush') | ||
} | ||
|
||
module.exports = createSuite(tests) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const expectTimeout = require('../utils/expect-timeout') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
const fs = require('fs') | ||
const os = require('os') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.addFromFs', function () { | ||
this.timeout(40 * 1000) | ||
|
||
const fixturesPath = path.join(__dirname, '../../test/fixtures') | ||
let ipfs | ||
|
||
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) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist() | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should add a directory from the file system', (done) => { | ||
const filesPath = path.join(fixturesPath, 'test-folder') | ||
ipfs.addFromFs(filesPath, { recursive: true }, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.be.above(8) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should add a directory from the file system with an odd name', (done) => { | ||
const filesPath = path.join(fixturesPath, 'weird name folder [v0]') | ||
ipfs.addFromFs(filesPath, { recursive: true }, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.be.above(8) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should ignore a directory from the file system', (done) => { | ||
const filesPath = path.join(fixturesPath, 'test-folder') | ||
ipfs.addFromFs(filesPath, { recursive: true, ignore: ['files/**'] }, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.be.below(9) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should add a file from the file system', (done) => { | ||
const filePath = path.join(fixturesPath, 'testfile.txt') | ||
ipfs.addFromFs(filePath, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.equal(1) | ||
expect(result[0].path).to.equal('testfile.txt') | ||
done() | ||
}) | ||
}) | ||
|
||
it('should add a hidden file in a directory from the file system', (done) => { | ||
const filesPath = path.join(fixturesPath, 'hidden-files-folder') | ||
ipfs.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.be.above(10) | ||
expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt') | ||
expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') | ||
done() | ||
}) | ||
}) | ||
|
||
it('should add a file from the file system with only-hash=true', function () { | ||
this.slow(10 * 1000) | ||
|
||
const content = String(Math.random() + Date.now()) | ||
const filepath = path.join(os.tmpdir(), `${content}.txt`) | ||
fs.writeFileSync(filepath, content) | ||
|
||
return ipfs.addFromFs(filepath, { onlyHash: true }) | ||
.then(out => { | ||
fs.unlinkSync(filepath) | ||
return expectTimeout(ipfs.object.get(out[0].hash), 4000) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const loadFixture = require('aegir/fixtures') | ||
const into = require('into-stream') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.addFromStream', function () { | ||
this.timeout(40 * 1000) | ||
|
||
let ipfs | ||
|
||
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) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist() | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should add from a stream', (done) => { | ||
const testData = loadFixture('js/test/fixtures/15mb.random', 'interface-ipfs-core') | ||
|
||
ipfs.addFromStream(into(testData), (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.length).to.equal(1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.