From 42ead41a46a48b2e0ebc6aa7ab1456a5de3d1b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Cuadros?= Date: Thu, 22 Apr 2021 02:15:16 +0200 Subject: [PATCH] osfs: fix js implementation based on menfs --- osfs/os_js.go | 12 +++--------- osfs/os_js_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ osfs/os_plan9.go | 2 ++ osfs/os_test.go | 2 ++ 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 osfs/os_js_test.go diff --git a/osfs/os_js.go b/osfs/os_js.go index 1044b71..e4d92fd 100644 --- a/osfs/os_js.go +++ b/osfs/os_js.go @@ -1,3 +1,5 @@ +// +build js + package osfs import ( @@ -9,15 +11,7 @@ import ( // globalMemFs is the global memory fs var globalMemFs = memfs.New() -const ( - defaultDirectoryMode = 0755 - defaultCreateMode = 0666 -) - -// OS is a filesystem shim for js. -type OS struct{} - // New returns a new OS filesystem. func New(baseDir string) billy.Filesystem { - return chroot.New(globalMemFs, baseDir) + return chroot.New(globalMemFs, globalMemFs.Join("/", baseDir)) } diff --git a/osfs/os_js_test.go b/osfs/os_js_test.go new file mode 100644 index 0000000..84a8190 --- /dev/null +++ b/osfs/os_js_test.go @@ -0,0 +1,47 @@ +// +build js + +package osfs + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/go-git/go-billy/v5" + "github.com/go-git/go-billy/v5/test" + + . "gopkg.in/check.v1" +) + +func Test(t *testing.T) { TestingT(t) } + +type OSSuite struct { + test.FilesystemSuite + path string + tempCounter int +} + +var _ = Suite(&OSSuite{}) + +func (s *OSSuite) SetUpTest(c *C) { + s.tempCounter++ + s.path = fmt.Sprintf("test_%d", s.tempCounter) + s.FilesystemSuite = test.NewFilesystemSuite(New(s.path)) +} + +func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) { + _, err := s.FS.Open("dir/non-existent") + c.Assert(err, NotNil) + + _, err = s.FS.Stat(filepath.Join(s.path, "dir")) + c.Assert(os.IsNotExist(err), Equals, true) +} + +func (s *OSSuite) TestCapabilities(c *C) { + _, ok := s.FS.(billy.Capable) + c.Assert(ok, Equals, true) + + caps := billy.Capabilities(s.FS) + c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability) +} diff --git a/osfs/os_plan9.go b/osfs/os_plan9.go index fe1eb85..e8f519f 100644 --- a/osfs/os_plan9.go +++ b/osfs/os_plan9.go @@ -1,3 +1,5 @@ +// +build plan9 + package osfs import ( diff --git a/osfs/os_test.go b/osfs/os_test.go index 18e1397..b6f3dd9 100644 --- a/osfs/os_test.go +++ b/osfs/os_test.go @@ -1,3 +1,5 @@ +// +build !js + package osfs import (