-
Notifications
You must be signed in to change notification settings - Fork 17
/
fixtures_options.go
48 lines (42 loc) · 1.16 KB
/
fixtures_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package fixtures
import (
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git-fixtures/v5/internal/tgz"
)
type Option func(*options)
type options struct {
fsFactory func() (billy.Filesystem, error)
}
func newOptions() *options {
return &options{
fsFactory: tgz.MemFactory,
}
}
// WithMemFS returns the option of using memfs for the fs created for Fixtures.
func WithMemFS() Option {
return func(o *options) {
o.fsFactory = tgz.MemFactory
}
}
// WithTargetDir returns the option of using an OS-based filesystem based on a target dir.
// The target dir will be based on the name returned from dirName, which aligns with tempdir
// functions in different testing frameworks (e.g. t.TempDir, c.MkDir).
//
// The caller is responsible for removing the dir from disk. Therefore, it is recommended
// to delegate that to the testing framework:
//
// Go:
//
// WithTargetDir(t.TempDir)
//
// Check Framework:
//
// WithTargetDir(c.Mkdir)
func WithTargetDir(dirName func() string) Option {
return func(o *options) {
o.fsFactory = func() (billy.Filesystem, error) {
return osfs.New(dirName(), osfs.WithChrootOS()), nil
}
}
}