From 43b9ac25eb7792392c6d9f67fbe9fb6881505c5c Mon Sep 17 00:00:00 2001 From: onee-only Date: Tue, 5 Mar 2024 21:06:14 +0900 Subject: [PATCH] Update memfs.New() to create root directory --- memfs/memory.go | 1 + memfs/memory_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/memfs/memory.go b/memfs/memory.go index 978fed1..2641238 100644 --- a/memfs/memory.go +++ b/memfs/memory.go @@ -29,6 +29,7 @@ type Memory struct { // New returns a new Memory filesystem. func New() billy.Filesystem { fs := &Memory{s: newStorage()} + fs.s.New("/", 0755|os.ModeDir, 0) return chroot.New(fs, string(separator)) } diff --git a/memfs/memory_test.go b/memfs/memory_test.go index 26f74ca..030c58a 100644 --- a/memfs/memory_test.go +++ b/memfs/memory_test.go @@ -27,6 +27,12 @@ func (s *MemorySuite) SetUpTest(c *C) { s.FilesystemSuite = test.NewFilesystemSuite(New()) } +func (s *MemorySuite) TestRootExists(c *C) { + f, err := s.FS.Stat("/") + c.Assert(err, IsNil) + c.Assert(f.IsDir(), Equals, true) +} + func (s *MemorySuite) TestCapabilities(c *C) { _, ok := s.FS.(billy.Capable) c.Assert(ok, Equals, true)