From 6d89040f9104ac4ec55e12bee5665388d351d8ff Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 17 Dec 2018 12:37:08 +0000 Subject: [PATCH 1/2] test: add symlink tests License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/add-from-fs.js | 34 ++++++++++++++++++- js/test/fixtures/symlinks/ipfs.txt-link | 1 + js/test/fixtures/symlinks/real-dir-link | 1 + .../fixtures/symlinks/real-dir/real-file.txt | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) create mode 120000 js/test/fixtures/symlinks/ipfs.txt-link create mode 120000 js/test/fixtures/symlinks/real-dir-link create mode 100644 js/test/fixtures/symlinks/real-dir/real-file.txt diff --git a/js/src/files-regular/add-from-fs.js b/js/src/files-regular/add-from-fs.js index b2f35cfa..f8c252ac 100644 --- a/js/src/files-regular/add-from-fs.js +++ b/js/src/files-regular/add-from-fs.js @@ -12,7 +12,7 @@ module.exports = (createCommon, options) => { const it = getIt(options) const common = createCommon() - describe('.addFromFs', function () { + describe.only('.addFromFs', function () { this.timeout(40 * 1000) const fixturesPath = path.join(__dirname, '../../test/fixtures') @@ -44,6 +44,38 @@ module.exports = (createCommon, options) => { }) }) + it('should add a symlink to a file', (done) => { + const filePath = path.join(fixturesPath, 'symlinks', 'ipfs.txt-link') + ipfs.addFromFs(filePath, (err, files) => { + expect(err).to.not.exist() + + const file = files.find(r => r.path === 'ipfs.txt-link') + expect(file).to.exist() + + ipfs.cat(file.hash, (err, data) => { + expect(err).to.not.exist() + expect(data.toString()).to.eql('IPFS\n') + done() + }) + }) + }) + + it('should add a symlink to a directory', (done) => { + const dirPath = path.join(fixturesPath, 'symlinks', 'real-dir-link') + ipfs.addFromFs(dirPath, { recursive: true }, (err, files) => { + expect(err).to.not.exist() + + const file = files.find(r => r.path === 'real-dir-link/real-file.txt') + expect(file).to.exist() + + ipfs.cat(file.hash, (err, data) => { + expect(err).to.not.exist() + expect(data.toString()).to.eql('A real file\n') + 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) => { diff --git a/js/test/fixtures/symlinks/ipfs.txt-link b/js/test/fixtures/symlinks/ipfs.txt-link new file mode 120000 index 00000000..a3cec95c --- /dev/null +++ b/js/test/fixtures/symlinks/ipfs.txt-link @@ -0,0 +1 @@ +../test-folder/files/ipfs.txt \ No newline at end of file diff --git a/js/test/fixtures/symlinks/real-dir-link b/js/test/fixtures/symlinks/real-dir-link new file mode 120000 index 00000000..08ca8430 --- /dev/null +++ b/js/test/fixtures/symlinks/real-dir-link @@ -0,0 +1 @@ +real-dir \ No newline at end of file diff --git a/js/test/fixtures/symlinks/real-dir/real-file.txt b/js/test/fixtures/symlinks/real-dir/real-file.txt new file mode 100644 index 00000000..6fdea282 --- /dev/null +++ b/js/test/fixtures/symlinks/real-dir/real-file.txt @@ -0,0 +1 @@ +A real file From 2530eee01a0d931801f7186656aeab5929ca08c6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 17 Dec 2018 12:40:46 +0000 Subject: [PATCH 2/2] chore: remove .only License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/add-from-fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/files-regular/add-from-fs.js b/js/src/files-regular/add-from-fs.js index f8c252ac..768277a0 100644 --- a/js/src/files-regular/add-from-fs.js +++ b/js/src/files-regular/add-from-fs.js @@ -12,7 +12,7 @@ module.exports = (createCommon, options) => { const it = getIt(options) const common = createCommon() - describe.only('.addFromFs', function () { + describe('.addFromFs', function () { this.timeout(40 * 1000) const fixturesPath = path.join(__dirname, '../../test/fixtures')