-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The refactoring achieves a few goals: - Support for fully in-memory execution, without the need of extracting tgz files into disk. - Removal of the deprecated check.v1 dependency. Signed-off-by: Paulo Gomes <[email protected]>
- Loading branch information
Showing
11 changed files
with
304 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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/v4/internal/tgz" | ||
) | ||
|
||
const ( | ||
useDefaultTempDir = "" | ||
tmpPrefix = "tmp-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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.