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
Add failing get recursive test #736
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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,99 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const pull = require('pull-stream') | ||
const series = require('async/series') | ||
const concat = require('concat-stream') | ||
const through = require('through2') | ||
|
||
const IPFS = require('../../src/core') | ||
const createTempRepo = require('../utils/create-repo-node.js') | ||
|
||
describe('files', () => { | ||
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK' | ||
let ipfs | ||
|
||
before((done) => { | ||
const repo = createTempRepo() | ||
ipfs = new IPFS(repo) | ||
series([ | ||
(cb) => ipfs.init({ bits: 1024 }, cb), | ||
(cb) => ipfs.load(cb) | ||
], done) | ||
}) | ||
|
||
it('can add deeply nested heterogeneous dirs', done => { | ||
const files = [ | ||
{ path: 'a/b/c/d/e', content: pull.values([new Buffer('banana')]) }, | ||
{ path: 'a/b/c/d/f', content: pull.values([new Buffer('strawberry')]) }, | ||
{ path: 'a/b/g', content: pull.values([new Buffer('ice')]) }, | ||
{ path: 'a/b/h', content: pull.values([new Buffer('cream')]) } | ||
] | ||
|
||
ipfs.files.add(files, (err, res) => { | ||
expect(err).to.not.exist | ||
const root = res[res.length - 1] | ||
|
||
expect(root.path).to.equal('a') | ||
expect(root.hash).to.equal(rootHash) | ||
done() | ||
}) | ||
}) | ||
|
||
it('can export that dir', done => { | ||
ipfs.files.get(rootHash, (err, stream) => { | ||
expect(err).to.not.exist | ||
|
||
// accumulate the files and their content | ||
var files = [] | ||
stream.pipe(through.obj((file, enc, next) => { | ||
if (file.content) { | ||
file.content.pipe(concat((content) => { | ||
files.push({ | ||
path: file.path, | ||
content: content | ||
}) | ||
next() | ||
})) | ||
} else { | ||
files.push(file) | ||
next() | ||
} | ||
}, () => { | ||
files = files.sort(byPath) | ||
// Check paths | ||
var paths = files.map((file) => file.path) | ||
expect(paths).to.include.members([ | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c/d', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c/d/e', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c/d/f', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/g', | ||
'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/h' | ||
]) | ||
|
||
// Check contents | ||
var contents = files.map(function (file) { | ||
return file.content ? file.content.toString() : null | ||
}) | ||
|
||
expect(contents).to.include.members([ | ||
'banana', | ||
'strawberry', | ||
'ice', | ||
'cream' | ||
]) | ||
done() | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
function byPath (a, b) { | ||
if (a.path > b.path) return 1 | ||
if (a.path < b.path) return -1 | ||
return 0 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victorbjelkholm your turn, tests are passing :)
(also, make sure to unlink to delete that file, like the other tests do.