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

Commit

Permalink
feat: More stat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Apr 16, 2018
1 parent 2ea064b commit d4fc07e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 39 additions & 3 deletions test/stat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
})
})

Expand Down Expand Up @@ -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')
})
})
})
13 changes: 8 additions & 5 deletions test/write.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
})

Expand All @@ -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)
Expand All @@ -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, {
Expand Down

0 comments on commit d4fc07e

Please sign in to comment.