From d4fc07e708da3f3d19385b40deccb48673d219b2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 16 Apr 2018 16:02:18 +0100 Subject: [PATCH] feat: More stat tests --- package.json | 1 + test/stat.spec.js | 42 +++++++++++++++++++++++++++++++++++++++--- test/write.spec.js | 13 ++++++++----- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1e8fb6f..3970882 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "aegir": "^13.0.6", "chai": "^4.1.2", "dirty-chai": "^2.0.1", + "fs-extra": "^5.0.0", "ipfs": "^0.28.2", "pre-commit": "^1.2.2", "safe-buffer": "^5.1.1", diff --git a/test/stat.spec.js b/test/stat.spec.js index 1f1664c..892dc96 100644 --- a/test/stat.spec.js +++ b/test/stat.spec.js @@ -4,6 +4,8 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect +const fs = require('fs') +const path = require('path') const { createMfs, @@ -14,11 +16,19 @@ describe('stat', function () { this.timeout(30000) let mfs + let smallFile + let largeFile before(() => { - return createMfs() - .then(instance => { + return Promise.all([ + createMfs(), + fs.readFile(path.join(__dirname, 'fixtures', 'small-file.txt')), + fs.readFile(path.join(__dirname, 'fixtures', 'large-file.jpg')) + ]) + .then(([instance, smallFileBuffer, largeFileBuffer]) => { mfs = instance + smallFile = smallFileBuffer + largeFile = largeFileBuffer }) }) @@ -93,7 +103,33 @@ describe('stat', function () { }) - it.skip('stats a file', () => { + it('stats a small file', () => { + const filePath = '/stat/small-file.txt' + return mfs.write(filePath, smallFile, { + parents: true + }) + .then(() => mfs.stat(filePath)) + .then((stats) => { + expect(stats.size).to.equal(smallFile.length) + expect(stats.cumulativeSize).to.equal(21) + expect(stats.childBlocks).to.equal(0) + expect(stats.type).to.equal('file') + }) + }) + + it('stats a large file', () => { + const filePath = '/stat/large-file.txt' + + return mfs.write(filePath, largeFile, { + parents: true + }) + .then(() => mfs.stat(filePath)) + .then((stats) => { + expect(stats.size).to.equal(largeFile.length) + expect(stats.cumulativeSize).to.equal(490800) + expect(stats.childBlocks).to.equal(2) + expect(stats.type).to.equal('file') + }) }) }) diff --git a/test/write.spec.js b/test/write.spec.js index 83a0eaa..7152c90 100644 --- a/test/write.spec.js +++ b/test/write.spec.js @@ -5,7 +5,7 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect const path = require('path') -const fs = require('fs') +const fs = require('fs-extra') const { createMfs @@ -15,11 +15,16 @@ describe('write', function () { this.timeout(30000) let mfs + let smallFile before(() => { - return createMfs() - .then(instance => { + return Promise.all([ + createMfs(), + fs.readFile(path.join(__dirname, 'fixtures', 'small-file.txt')) + ]) + .then(([instance, smallFileBuffer]) => { mfs = instance + smallFile = smallFileBuffer }) }) @@ -28,7 +33,6 @@ describe('write', function () { }) it('writes a small file', () => { - const smallFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'small-file.txt')) const filePath = '/small-file.txt' return mfs.write(filePath, smallFile) @@ -39,7 +43,6 @@ describe('write', function () { }) it('writes a deeply nested small file', () => { - const smallFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'small-file.txt')) const filePath = '/foo/bar/baz/qux/quux/garply/small-file.txt' return mfs.write(filePath, smallFile, {