Skip to content

Commit 8a402b8

Browse files
committed
expose temp filesystem
1 parent 192ee1a commit 8a402b8

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

fixtures.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
//go:generate esc -o data.go -pkg=fixtures data
1616

1717
var (
18-
files = make(map[string]string)
19-
fs = osfs.New(os.TempDir())
18+
files = make(map[string]string)
19+
Filesystem = osfs.New(os.TempDir())
2020
)
2121

2222
var fixtures = Fixtures{{
@@ -207,15 +207,15 @@ func (f *Fixture) Is(tag string) bool {
207207

208208
func (f *Fixture) file(path string) (billy.File, error) {
209209
if fpath, ok := files[path]; ok {
210-
return fs.Open(fpath)
210+
return Filesystem.Open(fpath)
211211
}
212212

213213
bytes, err := FSByte(false, "/data/"+path)
214214
if err != nil {
215215
return nil, err
216216
}
217217

218-
file, err := fs.TempFile("", "go-git-fixtures")
218+
file, err := Filesystem.TempFile("", "go-git-fixtures")
219219
if err != nil {
220220
return nil, err
221221
}
@@ -229,7 +229,7 @@ func (f *Fixture) file(path string) (billy.File, error) {
229229
}
230230

231231
files[path] = file.Name()
232-
return fs.Open(file.Name())
232+
return Filesystem.Open(file.Name())
233233
}
234234

235235
func (f *Fixture) Packfile() billy.File {
@@ -263,7 +263,7 @@ func (f *Fixture) DotGit() billy.Filesystem {
263263
panic(err)
264264
}
265265

266-
fs, err := tgz.Extract(fs, file.Name())
266+
fs, err := tgz.Extract(Filesystem, file.Name())
267267
if err != nil {
268268
panic(err)
269269
}
@@ -303,7 +303,7 @@ func (f *Fixture) Worktree() billy.Filesystem {
303303
panic(err)
304304
}
305305

306-
fs, err := tgz.Extract(fs, file.Name())
306+
fs, err := tgz.Extract(Filesystem, file.Name())
307307
if err != nil {
308308
panic(err)
309309
}
@@ -359,7 +359,7 @@ func (g Fixtures) Exclude(tag string) Fixtures {
359359
// Clean cleans all the temporal files created
360360
func Clean() error {
361361
for fname, f := range files {
362-
if err := fs.Remove(f); err != nil {
362+
if err := Filesystem.Remove(f); err != nil {
363363
return err
364364
}
365365
delete(files, fname)

fixtures_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fixtures
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestDotGit(t *testing.T) {
10+
fs := Basic().One().DotGit()
11+
files, err := fs.ReadDir("/")
12+
assert.NoError(t, err)
13+
assert.True(t, len(files) > 1)
14+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.14
44

55
require (
66
github.com/go-git/go-billy/v5 v5.2.0
7+
github.com/stretchr/testify v1.7.0 // indirect
78
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
89
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
24
github.com/go-git/go-billy/v5 v5.2.0 h1:GcoouCP9J+5slw2uXAocL70z8ml4A8B/H8nEPt6CLPk=
35
github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
46
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -8,8 +10,16 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
810
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
911
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1012
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1118
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
1219
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
20+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1321
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1422
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
1523
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
24+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
25+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)