Commit 5531575a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: test NotifyContent

parent 8b325003
...@@ -62,28 +62,31 @@ func (f *keepCacheFile) Read(ctx context.Context, fh FileHandle, dest []byte, of ...@@ -62,28 +62,31 @@ func (f *keepCacheFile) Read(ctx context.Context, fh FileHandle, dest []byte, of
type keepCacheRoot struct { type keepCacheRoot struct {
DefaultOperations DefaultOperations
keep, nokeep *keepCacheFile
} }
func (r *keepCacheRoot) OnAdd() { func (r *keepCacheRoot) OnAdd() {
i := InodeOf(r) i := InodeOf(r)
f1 := &keepCacheFile{ r.keep = &keepCacheFile{
keepCache: true, keepCache: true,
} }
f1.setContent(0) r.keep.setContent(0)
i.AddChild("keep", i.NewInode(f1, NodeAttr{}), true) i.AddChild("keep", i.NewInode(r.keep, NodeAttr{}), true)
f2 := &keepCacheFile{ r.nokeep = &keepCacheFile{
keepCache: false, keepCache: false,
} }
f2.setContent(0) r.nokeep.setContent(0)
i.AddChild("nokeep", i.NewInode(f2, NodeAttr{}), true) i.AddChild("nokeep", i.NewInode(r.nokeep, NodeAttr{}), true)
} }
func TestKeepCache(t *testing.T) { func TestKeepCache(t *testing.T) {
mntDir := testutil.TempDir() mntDir := testutil.TempDir()
sec := time.Second sec := time.Second
rawFS := NewNodeFS(&keepCacheRoot{}, &Options{ root := &keepCacheRoot{}
rawFS := NewNodeFS(root, &Options{
Debug: testutil.VerboseTest(), Debug: testutil.VerboseTest(),
FirstAutomaticIno: 1, FirstAutomaticIno: 1,
...@@ -118,6 +121,18 @@ func TestKeepCache(t *testing.T) { ...@@ -118,6 +121,18 @@ func TestKeepCache(t *testing.T) {
t.Errorf("keep read 2 got %q want read 1 %q", c2, c1) t.Errorf("keep read 2 got %q want read 1 %q", c2, c1)
} }
if s := InodeOf(root.keep).NotifyContent(0, 100); !s.Ok() {
t.Errorf("NotifyContent: %v", s)
}
c3, err := ioutil.ReadFile(mntDir + "/keep")
if err != nil {
t.Fatalf("read keep 3: %v", err)
}
if bytes.Compare(c2, c3) == 0 {
t.Errorf("keep read 3 got %q want different", c3)
}
nc1, err := ioutil.ReadFile(mntDir + "/nokeep") nc1, err := ioutil.ReadFile(mntDir + "/nokeep")
if err != nil { if err != nil {
t.Fatalf("read keep 1: %v", err) t.Fatalf("read keep 1: %v", err)
......
...@@ -538,9 +538,6 @@ func TestNotifyEntry(t *testing.T) { ...@@ -538,9 +538,6 @@ func TestNotifyEntry(t *testing.T) {
} }
} }
// XXX Test Notify() , but requires KEEP_CACHE ? or could use mmap?
// XXX Test NotifyDelete?
func TestReadDir(t *testing.T) { func TestReadDir(t *testing.T) {
tc := newTestCase(t, true, true) tc := newTestCase(t, true, true)
defer tc.Clean() defer tc.Clean()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment