From 7c5122114ec8c9caf773f2b329f45307944b6428 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Tue, 29 Aug 2023 22:23:31 +0100 Subject: [PATCH] Re-introduce osfs.Default The Default var was incorrectly removed as part of #31. This PR revert that change and adds tests to avoid future regression. Signed-off-by: Paulo Gomes --- osfs/os.go | 3 +++ osfs/os_js_test.go | 14 ++++++++++++++ osfs/os_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 osfs/os_test.go diff --git a/osfs/os.go b/osfs/os.go index 32ea0e5..cb7489a 100644 --- a/osfs/os.go +++ b/osfs/os.go @@ -18,6 +18,9 @@ const ( defaultCreateMode = 0o666 ) +// Default Filesystem representing the root of the os filesystem. +var Default = &ChrootOS{} + // New returns a new OS filesystem. func New(baseDir string, opts ...Option) billy.Filesystem { o := &options{} diff --git a/osfs/os_js_test.go b/osfs/os_js_test.go index a62d103..5c46b78 100644 --- a/osfs/os_js_test.go +++ b/osfs/os_js_test.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "reflect" "testing" "github.com/go-git/go-billy/v5" @@ -46,3 +47,16 @@ func (s *OSSuite) TestCapabilities(c *C) { caps := billy.Capabilities(s.FS) c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability) } + +func TestDefault(t *testing.T) { + want := &helper.ChrootHelper{} // chroot + memfs + got := Default + + if reflect.TypeOf(got) != reflect.TypeOf(want) { + t.Errorf("wanted Default to be %T got %T", want, got) + } +} + +func TestNewAPI(t *testing.T) { + _ = New("/") +} diff --git a/osfs/os_test.go b/osfs/os_test.go new file mode 100644 index 0000000..81ecf62 --- /dev/null +++ b/osfs/os_test.go @@ -0,0 +1,24 @@ +//go:build !js +// +build !js + +package osfs + +import ( + "reflect" + "testing" +) + +func TestDefault(t *testing.T) { + want := &ChrootOS{} + got := Default + + if reflect.TypeOf(got) != reflect.TypeOf(want) { + t.Errorf("wanted Default to be %T got %T", want, got) + } +} + +func TestNewAPI(t *testing.T) { + _ = New("/") + _ = New("/", WithBoundOS()) + _ = New("/", WithChrootOS()) +}