1
0
mirror of https://github.com/fuse-friends/fuse-native synced 2024-09-28 06:00:43 +00:00
fuse-friends_fuse-native/test/links.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-08-01 22:19:00 +00:00
const tape = require('tape')
const fs = require('fs')
const path = require('path')
2019-11-19 13:04:46 +00:00
const { unmount } = require('./helpers')
2019-08-01 22:19:00 +00:00
const Fuse = require('../')
const mnt = require('./fixtures/mnt')
const stat = require('./fixtures/stat')
2019-08-01 12:24:01 +00:00
tape('readlink', function (t) {
var ops = {
force: true,
readdir: function (path, cb) {
2019-08-06 08:55:08 +00:00
if (path === '/') return process.nextTick(cb, null, ['hello', 'link'])
return process.nextTick(cb, Fuse.ENOENT)
2019-08-01 12:24:01 +00:00
},
readlink: function (path, cb) {
2019-08-06 08:55:08 +00:00
process.nextTick(cb, 0, 'hello')
2019-08-01 12:24:01 +00:00
},
getattr: function (path, cb) {
2019-08-06 08:55:08 +00:00
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)
2019-08-01 12:24:01 +00:00
},
open: function (path, flags, cb) {
2019-08-06 08:55:08 +00:00
process.nextTick(cb, 0, 42)
2019-08-01 12:24:01 +00:00
},
read: function (path, fd, buf, len, pos, cb) {
var str = 'hello world'.slice(pos, pos + len)
2019-08-06 08:55:08 +00:00
if (!str) return process.nextTick(cb, 0)
2019-08-01 12:24:01 +00:00
buf.write(str)
2019-08-06 08:55:08 +00:00
return process.nextTick(cb, str.length)
2019-08-01 12:24:01 +00:00
}
}
2019-08-01 22:19:00 +00:00
const fuse = new Fuse(mnt, ops, { debug: true })
fuse.mount(function (err) {
2019-08-01 12:24:01 +00:00
t.error(err, 'no error')
fs.lstat(path.join(mnt, 'link'), function (err, stat) {
t.error(err, 'no error')
t.same(stat.size, 5, 'correct size')
fs.stat(path.join(mnt, 'hello'), function (err, stat) {
t.error(err, 'no error')
t.same(stat.size, 11, 'correct size')
fs.readlink(path.join(mnt, 'link'), function (err, dest) {
t.error(err, 'no error')
t.same(dest, 'hello', 'link resolves')
fs.readFile(path.join(mnt, 'link'), function (err, buf) {
t.error(err, 'no error')
2019-08-06 08:55:08 +00:00
t.same(buf, Buffer.from('hello world'), 'can read link content')
2019-08-01 12:24:01 +00:00
2019-11-19 13:04:46 +00:00
unmount(fuse, function () {
2019-08-01 12:24:01 +00:00
t.end()
})
})
})
})
})
})
})