initial tests

Mathias Buus 9 years ago
parent f3291fc28a
commit 89b6b675d2

@ -4,7 +4,7 @@
"description": "Fully maintained fuse bindings for Node that aims to cover the entire FUSE api",
"main": "index.js",
"scripts": {
"test": "standard"
"test": "standard && tape test/*.js"
},
"gypfile": true,
"dependencies": {
@ -13,7 +13,9 @@
"xtend": "^4.0.0"
},
"devDependencies": {
"standard": "^3.2.0"
"concat-stream": "^1.4.7",
"standard": "^3.2.0",
"tape": "^3.5.0"
},
"repository": {
"type": "git",

@ -0,0 +1,13 @@
var os = require('os')
var path = require('path')
var fs = require('fs')
var mnt = path.join(os.tmpdir(), 'fuse-bindings-' + process.pid + '-' + Date.now())
try {
fs.mkdirSync(mnt)
} catch (err) {
// do nothing
}
module.exports = mnt

@ -0,0 +1,11 @@
module.exports = function (st) {
return {
mtime: st.mtime || new Date(),
atime: st.atime || new Date(),
ctime: st.ctime || new Date(),
size: st.size !== undefined ? st.size : 0,
mode: st.mode === 'dir' ? 16877 : (st.mode === 'file' ? 33188 : st.mode),
uid: st.uid !== undefined ? st.uid : process.getuid(),
gid: st.gid !== undefined ? st.gid : process.getgid()
}
}

@ -0,0 +1,43 @@
var mnt = require('./fixtures/mnt')
var fuse = require('../')
var tape = require('tape')
tape('mount', function (t) {
fuse.mount(mnt, {force: true}, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
t.end()
})
})
})
tape('mount + unmount + mount', function (t) {
fuse.mount(mnt, {force: true}, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
fuse.mount(mnt, {force: true}, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
t.end()
})
})
})
})
})
tape('mnt point must exist', function (t) {
fuse.mount(mnt + '.does-not-exist', {}, function (err) {
t.ok(err, 'had error')
t.end()
})
})
tape('mnt point must be directory', function (t) {
fuse.mount(__filename, {}, function (err) {
t.ok(err, 'had error')
t.end()
})
})

@ -0,0 +1,61 @@
var mnt = require('./fixtures/mnt')
var stat = require('./fixtures/stat')
var fuse = require('../')
var tape = require('tape')
var fs = require('fs')
var path = require('path')
var concat = require('concat-stream')
tape('read', function (t) {
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, ['test'])
return cb(fuse.ENOENT)
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
if (path === '/test') return cb(null, stat({mode: 'file', size: 11}))
return cb(fuse.ENOENT)
},
open: function (path, flags, cb) {
cb(0, 42)
},
release: function (path, fd, cb) {
t.same(fd, 42, 'fd was passed to release')
cb(0)
},
read: function (path, fd, buf, len, pos, cb) {
var str = 'hello world'.slice(pos, pos + len)
if (!str) return cb(0)
buf.write(str)
return cb(str.length)
}
}
fuse.mount(mnt, ops, function (err) {
t.error(err, 'no error')
fs.readFile(path.join(mnt, 'test'), function (err, buf) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'read file')
fs.readFile(path.join(mnt, 'test'), function (err, buf) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'read file again')
fs.createReadStream(path.join(mnt, 'test'), {start: 0, end: 4}).pipe(concat(function (buf) {
t.same(buf, new Buffer('hello'), 'partial read file')
fs.createReadStream(path.join(mnt, 'test'), {start: 6, end: 10}).pipe(concat(function (buf) {
t.same(buf, new Buffer('world'), 'partial read file + start offset')
fuse.unmount(mnt, function () {
t.end()
})
}))
}))
})
})
})
})

@ -0,0 +1,54 @@
var mnt = require('./fixtures/mnt')
var stat = require('./fixtures/stat')
var fuse = require('../')
var tape = require('tape')
var fs = require('fs')
var path = require('path')
tape('write', function (t) {
var created = false
var data = new Buffer(1024)
var size = 0
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, created ? ['hello'] : [])
return cb(fuse.ENOENT)
},
truncate: function (path, size, cb) {
cb(0)
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
if (path === '/hello' && created) return cb(null, stat({mode: 'file', size: size}))
return cb(fuse.ENOENT)
},
create: function (path, flags, cb) {
t.ok(!created, 'file not created yet')
created = true
cb(0, 42)
},
release: function (path, fd, cb) {
cb(0)
},
write: function (path, fd, buf, len, pos, cb) {
buf.slice(0, len).copy(data, pos)
size = Math.max(pos + len, size)
cb(buf.length)
}
}
fuse.mount(mnt, ops, function (err) {
t.error(err, 'no error')
fs.writeFile(path.join(mnt, 'hello'), 'hello world', function (err) {
t.error(err, 'no error')
t.same(data.slice(0, size), new Buffer('hello world'), 'data was written')
fuse.unmount(mnt, function () {
t.end()
})
})
})
})
Loading…
Cancel
Save