lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit f285e8682be36f29eae75e2671cda5efbb984083
parent 4eba7dde4a57d0f160f6bca86c6c9a24ab8826f0
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  5 Jan 2024 12:15:37 +0900

add client.TestClose

Diffstat:
Mclient/file_test.go | 38++++++++++++++++++++++++++++++++++++++
Mclient/fs_test.go | 7+++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/client/file_test.go b/client/file_test.go @@ -109,3 +109,40 @@ L: t.Errorf("file name not in the testfs: %s", f.Name()) } } + +func TestClose(t *testing.T) { + cfs, cancel, err := mount(testfs) + if err != nil { + t.Fatal(err) + } + defer cancel() + defer cfs.Unmount() + var walk = func(path string, d fs.DirEntry, err error) error { + if err != nil { + if err == io.EOF { + return nil + } + return err + } + tf, err := testfs.walkPath(path) + if err != nil { + t.Error(err) + return nil + } + cf, err := cfs.OpenFile(path, lib9p.OREAD) + if err != nil { + if strings.Contains(err.Error(), "permission") { + return nil + } + return err + } + cc := make(chan struct{}) + tf.closec = cc + cf.Close() + <-cc + return nil + } + if err := fs.WalkDir(lib9p.ExportFS{cfs}, ".", walk); err != nil { + t.Error(err) + } +} +\ No newline at end of file diff --git a/client/fs_test.go b/client/fs_test.go @@ -28,6 +28,9 @@ type testFile struct { r *bytes.Reader // stat is the Stat of this testFile. stat lib9p.Stat + // closec is used by TestClose to check if *File.Close from the client + // invokes *testFile.Close at the server side. + closec chan struct{} } func (f *testFile) Stat() (*lib9p.FileInfo, error) { @@ -35,6 +38,10 @@ func (f *testFile) Stat() (*lib9p.FileInfo, error) { } func (f *testFile) Close() error { + if f.closec != nil { + close(f.closec) + } + f.closec = nil f.r = nil return nil }