Skip to content

Commit 36e04f4

Browse files
committed
Re-introduce osfs.Default
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]>
1 parent 1d4d3d3 commit 36e04f4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

osfs/os.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
defaultCreateMode = 0o666
1919
)
2020

21+
// Default Filesystem representing the root of the os filesystem.
22+
var Default = &ChrootOS{}
23+
2124
// New returns a new OS filesystem.
2225
func New(baseDir string, opts ...Option) billy.Filesystem {
2326
o := &options{}

osfs/os_js_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"reflect"
1011
"testing"
1112

1213
"github.com/go-git/go-billy/v5"
14+
"github.com/go-git/go-billy/v5/helper"
1315
"github.com/go-git/go-billy/v5/test"
1416

1517
. "gopkg.in/check.v1"
@@ -46,3 +48,16 @@ func (s *OSSuite) TestCapabilities(c *C) {
4648
caps := billy.Capabilities(s.FS)
4749
c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability)
4850
}
51+
52+
func TestDefault(t *testing.T) {
53+
want := &helper.ChrootHelper{} // chroot + memfs
54+
got := Default
55+
56+
if reflect.TypeOf(got) != reflect.TypeOf(want) {
57+
t.Errorf("wanted Default to be %T got %T", want, got)
58+
}
59+
}
60+
61+
func TestNewAPI(t *testing.T) {
62+
_ = New("/")
63+
}

osfs/os_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build !js
2+
// +build !js
3+
4+
package osfs
5+
6+
import (
7+
"reflect"
8+
"testing"
9+
)
10+
11+
func TestDefault(t *testing.T) {
12+
want := &ChrootOS{}
13+
got := Default
14+
15+
if reflect.TypeOf(got) != reflect.TypeOf(want) {
16+
t.Errorf("wanted Default to be %T got %T", want, got)
17+
}
18+
}
19+
20+
func TestNewAPI(t *testing.T) {
21+
_ = New("/")
22+
_ = New("/", WithBoundOS())
23+
_ = New("/", WithChrootOS())
24+
}

0 commit comments

Comments
 (0)