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 <pjbgf@linux.com>
  • Loading branch information
pjbgf committed Aug 29, 2023
1 parent 1d4d3d3 commit c02c696
Show file tree
Hide file tree
Showing 3 changed files with 42 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
15 changes: 15 additions & 0 deletions osfs/os_js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"
"testing"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-billy/v5/test"

. "gopkg.in/check.v1"
Expand Down Expand Up @@ -46,3 +48,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 := &memfs.Memory{}
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 c02c696

Please sign in to comment.