Skip to content

Commit

Permalink
Update memfs.New() to create root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
onee-only committed Mar 5, 2024
1 parent 9f60ea9 commit 43b9ac2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
6 changes: 6 additions & 0 deletions memfs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 43b9ac2

Please sign in to comment.