diff options
Diffstat (limited to 'internal/testgit/repo_from_fixture.go')
| -rw-r--r-- | internal/testgit/repo_from_fixture.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/testgit/repo_from_fixture.go b/internal/testgit/repo_from_fixture.go new file mode 100644 index 00000000..887bf9a3 --- /dev/null +++ b/internal/testgit/repo_from_fixture.go @@ -0,0 +1,35 @@ +package testgit + +import ( + "io/fs" + "os" + "testing" + + "codeberg.org/lindenii/furgit/objectid" +) + +// NewRepoFromFixture copies one existing repository fixture into a temp dir. +func NewRepoFromFixture(tb testing.TB, algo objectid.Algorithm, fixtureDir string) *TestRepo { + tb.Helper() + + if algo.Size() == 0 { + tb.Fatalf("invalid algorithm: %v", algo) + } + + dst := tb.TempDir() + srcFS := os.DirFS(fixtureDir) + err := copyFS(dst, srcFS) + if err != nil { + tb.Fatalf("copy fixture %q: %v", fixtureDir, err) + } + + return &TestRepo{ + dir: dst, + algo: algo, + env: defaultEnv(), + } +} + +func copyFS(dst string, src fs.FS) error { + return os.CopyFS(dst, src) +} |
