Debian Codegraph @

fixtures_options.go

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