Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-introduce osfs.Default #33

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/helper/chroot"
"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 := &chroot.ChrootHelper{} // memfs is wrapped around ChrootHelper.
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())
}