/usr/share/gocode/src/github.com/hanwen/go-fuse/fuse/test/defaultnode_test.go is in golang-github-hanwen-go-fuse-dev 0.0~git20171124.0.14c3015-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | // Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package test
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
)
func TestDefaultNodeGetAttr(t *testing.T) {
dir := testutil.TempDir()
defer os.RemoveAll(dir)
opts := &nodefs.Options{
// Note: defaultNode.GetAttr() calling file.GetAttr() is only useful if
// AttrTimeout is zero.
// See https://github.com/JonathonReinhart/gitlab-fuse/issues/2
Owner: fuse.CurrentOwner(),
Debug: testutil.VerboseTest(),
}
root := nodefs.NewDefaultNode()
s, _, err := nodefs.MountRoot(dir, root, opts)
if err != nil {
t.Fatalf("MountRoot: %v", err)
}
go s.Serve()
if err := s.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
defer s.Unmount()
// Attach another custom node type
root.Inode().NewChild("foo", false, &myNode{
Node: nodefs.NewDefaultNode(),
content: []byte("success"),
})
filepath := path.Join(dir, "foo")
// NewDefaultNode() should provide for stat that indicates 0-byte regular file
fi, err := os.Stat(filepath)
if err != nil {
t.Fatalf("Stat: %v", err)
}
if mode := (fi.Mode() & os.ModeType); mode != 0 {
// Mode() & ModeType should be zero for regular files
t.Fatalf("Unexpected mode: %#o", mode)
}
if size := fi.Size(); size != 0 {
t.Fatalf("Unexpected size: %d", size)
}
// But when we open the file, we should get the content
content, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
if string(content) != "success" {
t.Fatalf("Unexpected content: %v", content)
}
}
type myNode struct {
nodefs.Node
content []byte
}
func (n *myNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
return nodefs.NewDataFile(n.content), fuse.OK
}
|