Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

test: add test for mfs leaf node types #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"stream-to-promise": "^2.2.0",
"transform-loader": "^0.2.4"
},
"dependencies": {},
"dependencies": {
"ipfs-unixfs": "^0.1.14"
},
"contributors": []
}
1 change: 1 addition & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
require('./kad-dht')
require('./circuit')
// require('./repo')
require('./mfs')
88 changes: 88 additions & 0 deletions test/mfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const waterfall = require('async/waterfall')
const crypto = require('crypto')
const os = require('os')
const path = require('path')
const hat = require('hat')
const UnixFs = require('ipfs-unixfs')

const DaemonFactory = require('ipfsd-ctl')
const goDf = DaemonFactory.create()
const jsDf = DaemonFactory.create({ type: 'js' })

function checkNodeTypes (api, hash, data, callback) {
waterfall([
(cb) => api.object.get(hash, cb),
(node, cb) => {
const meta = UnixFs.unmarshal(node.data)

expect(meta.type).to.equal('file')
expect(node.links.length).to.equal(2)

api.object.get(node.links[0].multihash, cb)
},
(child, cb) => {
const childMeta = UnixFs.unmarshal(child.data)

expect(childMeta.type).to.equal('raw')

cb()
}
], callback)
}

function addFile (daemon, dir, data, callback) {
let instance
const path = 'test-file'

waterfall([
(cb) => daemon.spawn({
repoPath: dir,
disposable: false,
initOptions: { bits: 1024 }
}, cb),
(node, cb) => {
instance = node
instance.init(cb)
},
(cb) => instance.start((error) => cb(error)),
(cb) => {
instance.api.files.write(`/${path}`, data, {
create: true
}, (error) => cb(error))
},
// cannot list file directly - https://github.com/ipfs/go-ipfs/issues/5044
(cb) => instance.api.files.ls(`/`, {
l: true
}, cb),
(files, cb) => checkNodeTypes(instance.api, files[0].hash, data, cb),
(cb) => instance.stop(cb)
], callback)
}

describe('mfs', () => {
it('mfs uses raw nodes for leaf data: go', function (done) {
this.timeout(50 * 1000)

const dir = path.join(os.tmpdir(), hat())
const data = crypto.randomBytes(1024 * 300)

addFile(goDf, dir, data, done)
})

it('mfs uses raw nodes for leaf data: js', function (done) {
this.timeout(50 * 1000)

const dir = path.join(os.tmpdir(), hat())
const data = crypto.randomBytes(1024 * 300)

addFile(jsDf, dir, data, done)
})
})
1 change: 1 addition & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ require('./repo')
require('./exchange-files')
require('./kad-dht')
require('./pubsub')
require('./mfs')