1
0
mirror of https://github.com/fuse-friends/fuse-native synced 2026-03-02 03:40:15 +00:00

tests all pass

This commit is contained in:
Andrew Osheroff
2019-08-06 10:55:08 +02:00
parent 97e42d4fb9
commit 2961856b5b
9 changed files with 250 additions and 195 deletions

View File

@@ -10,26 +10,26 @@ tape('readlink', function (t) {
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, ['hello', 'link'])
return cb(Fuse.ENOENT)
if (path === '/') return process.nextTick(cb, null, ['hello', 'link'])
return process.nextTick(cb, Fuse.ENOENT)
},
readlink: function (path, cb) {
cb(0, 'hello')
process.nextTick(cb, 0, 'hello')
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello') return cb(null, stat({ mode: 'file', size: 11 }))
if (path === '/link') return cb(null, stat({ mode: 'link', size: 5 }))
return cb(Fuse.ENOENT)
if (path === '/') return process.nextTick(cb, null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello') return process.nextTick(cb, null, stat({ mode: 'file', size: 11 }))
if (path === '/link') return process.nextTick(cb, null, stat({ mode: 'link', size: 5 }))
return process.nextTick(cb, Fuse.ENOENT)
},
open: function (path, flags, cb) {
cb(0, 42)
process.nextTick(cb, 0, 42)
},
read: function (path, fd, buf, len, pos, cb) {
var str = 'hello world'.slice(pos, pos + len)
if (!str) return cb(0)
if (!str) return process.nextTick(cb, 0)
buf.write(str)
return cb(str.length)
return process.nextTick(cb, str.length)
}
}
@@ -51,9 +51,9 @@ tape('readlink', function (t) {
fs.readFile(path.join(mnt, 'link'), function (err, buf) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'can read link content')
t.same(buf, Buffer.from('hello world'), 'can read link content')
fuse.unmount( function () {
fuse.unmount(function () {
t.end()
})
})

View File

@@ -1,26 +1,31 @@
var mnt = require('./fixtures/mnt')
var fuse = require('../')
var tape = require('tape')
var Fuse = require('../')
tape('mount', function (t) {
fuse.mount(mnt, { force: true }, function (err) {
const fuse = new Fuse(mnt, {}, { force: true })
fuse.mount(function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
fuse.unmount(function () {
t.end()
})
})
})
tape('mount + unmount + mount', function (t) {
fuse.mount(mnt, { force: true }, function (err) {
const fuse1 = new Fuse(mnt, {}, { force: true, debug: false })
const fuse2 = new Fuse(mnt, {}, { force: true, debug: false })
fuse1.mount(function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
fuse.mount(mnt, { force: true }, function (err) {
fuse1.unmount(function () {
fuse2.mount(function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
fuse2.unmount(function () {
t.end()
})
})
@@ -29,14 +34,16 @@ tape('mount + unmount + mount', function (t) {
})
tape('mnt point must exist', function (t) {
fuse.mount(mnt + '.does-not-exist', {}, function (err) {
const fuse = new Fuse('.does-not-exist', {}, { debug: false })
fuse.mount(function (err) {
t.ok(err, 'had error')
t.end()
})
})
tape('mnt point must be directory', function (t) {
fuse.mount(__filename, {}, function (err) {
const fuse = new Fuse(__filename, {}, { debug: false })
fuse.mount(function (err) {
t.ok(err, 'had error')
t.end()
})

View File

@@ -11,27 +11,27 @@ tape('read', function (t) {
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, ['test'])
return cb(Fuse.ENOENT)
if (path === '/') return process.nextTick(cb, null, ['test'])
return process.nextTick(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)
if (path === '/') return process.nextTick(cb, null, stat({ mode: 'dir', size: 4096 }))
if (path === '/test') return process.nextTick(cb, null, stat({ mode: 'file', size: 11 }))
return process.nextTick(cb, Fuse.ENOENT)
},
open: function (path, flags, cb) {
cb(0, 42)
return process.nextTick(cb, 0, 42)
},
release: function (path, fd, cb) {
console.log('IN JS RELEASE')
t.same(fd, 42, 'fd was passed to release')
cb(0)
return process.nextTick(cb, 0)
},
read: function (path, fd, buf, len, pos, cb) {
var str = 'hello world'.slice(pos, pos + len)
if (!str) return cb(0)
if (!str) return process.nextTick(cb, 0)
buf.write(str)
return cb(str.length)
return process.nextTick(cb, str.length)
}
}
@@ -41,17 +41,17 @@ tape('read', function (t) {
fs.readFile(path.join(mnt, 'test'), function (err, buf) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'read file')
t.same(buf, Buffer.from('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')
t.same(buf, Buffer.from('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')
t.same(buf, Buffer.from('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')
t.same(buf, Buffer.from('world'), 'partial read file + start offset')
fuse.unmount(function () {
t.end()

View File

@@ -8,35 +8,35 @@ const stat = require('./fixtures/stat')
tape('write', function (t) {
var created = false
var data = new Buffer(1024)
var data = Buffer.alloc(1024)
var size = 0
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, created ? ['hello'] : [])
return cb(Fuse.ENOENT)
if (path === '/') return process.nextTick(cb, null, created ? ['hello'] : [], [])
return process.nextTick(cb, Fuse.ENOENT)
},
truncate: function (path, size, cb) {
cb(0)
process.nextTick(cb, 0)
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello' && created) return cb(0, stat({ mode: 'file', size: size }))
return cb(Fuse.ENOENT)
if (path === '/') return process.nextTick(cb, null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello' && created) return process.nextTick(cb, 0, stat({ mode: 'file', size: size }))
return process.nextTick(cb, Fuse.ENOENT)
},
create: function (path, flags, cb) {
t.ok(!created, 'file not created yet')
created = true
cb(0, 42)
process.nextTick(cb, 0, 42)
},
release: function (path, fd, cb) {
cb(0)
process.nextTick(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)
process.nextTick(cb, buf.length)
}
}
@@ -46,7 +46,7 @@ tape('write', function (t) {
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')
t.same(data.slice(0, size), Buffer.from('hello world'), 'data was written')
fuse.unmount(function () {
t.end()