Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-11-14 20:26:10 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-11-16 18:49:20 +0300
commit858fe714e85cac0faa3cbb1a2df9c2dc73b4ebb5 (patch)
tree9bf0e39c5f8abf006c52407c2d1f62cbd58aa796 /internal/testhelper
parent98bb1e426854440526e67cb74d6655d076137015 (diff)
Add test helpers to clone the test repo on corrupting tests
Diffstat (limited to 'internal/testhelper')
-rw-r--r--internal/testhelper/testhelper.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index d75fd2030..9094c36ef 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -17,6 +17,7 @@ import (
"time"
log "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/require"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/internal/command"
@@ -297,3 +298,36 @@ func mustFindNoRunningChildProcess() {
func Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
+
+// SetupCopyTestRepo creates a bare copy of the test repository.
+func SetupCopyTestRepo(t *testing.T) (repo *pb.Repository, repoPath string, cleanup func()) {
+ return cloneTestRepo(t, true)
+}
+
+// SetupMutableTestRepo creates a copy of the test repository apt for changes.
+func SetupMutableTestRepo(t *testing.T) (repo *pb.Repository, repoPath string, cleanup func()) {
+ return cloneTestRepo(t, false)
+}
+
+func cloneTestRepo(t *testing.T, bare bool) (repo *pb.Repository, repoPath string, cleanup func()) {
+ testRepo := TestRepository()
+ storagePath := GitlabTestStoragePath()
+ testRepoPath := path.Join(storagePath, testRepo.RelativePath)
+
+ repoPath, err := ioutil.TempDir(storagePath, t.Name())
+ require.NoError(t, err)
+ relativePath, err := filepath.Rel(storagePath, repoPath)
+ require.NoError(t, err)
+ repo = &pb.Repository{StorageName: "default", RelativePath: relativePath}
+
+ args := []string{"clone"}
+ if bare {
+ args = append(args, "--bare")
+ } else {
+ // For non-bare repos the relative path is the .git folder inside the path
+ repo.RelativePath = path.Join(relativePath, ".git")
+ }
+ MustRunCommand(t, nil, "git", append(args, testRepoPath, repoPath)...)
+
+ return repo, repoPath, func() { os.RemoveAll(repoPath) }
+}