Skip to content

Commit

Permalink
Re-introduce osfs.Default
Browse files Browse the repository at this point in the history
The Default var was incorrectly removed as part of
go-git#31. This PR revert that change and adds tests to
avoid future regression.

Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
pjbgf committed Aug 29, 2023
1 parent 1d4d3d3 commit 7c51221
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions osfs/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
14 changes: 14 additions & 0 deletions osfs/os_js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"
"testing"

"github.com/go-git/go-billy/v5"
Expand Down Expand Up @@ -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

Check failure on line 52 in osfs/os_js_test.go

View workflow job for this annotation

GitHub Actions / test (1.20.x)

undefined: helper

Check failure on line 52 in osfs/os_js_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

undefined: helper
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("/")
}
24 changes: 24 additions & 0 deletions osfs/os_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 7c51221

Please sign in to comment.