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:
authorPaul Okstad <pokstad@gitlab.com>2020-01-06 16:06:20 +0300
committerJacob Vosmaer <jacob@gitlab.com>2020-01-06 16:06:20 +0300
commita4dd1d77e12d397b74e5fd20946ad0b28e697602 (patch)
tree85bf7fd390a049d94135da73414d28cd574ddbc5
parent7d19a5dd8a7ec6dabd63746801549a3740963c0c (diff)
Global temp directory for Gitaly tests
This changes the `testhelper.TempDir` Go function so that it creates all temp directories in a central location. This central location is modeled after the test repo convention (see references to TEST_REPO_STORAGE_PATH). This should allow for tests to create unique test folders for temporary files while allowing easy clean up via `make clean`.
-rw-r--r--internal/safe/file_writer_test.go8
-rw-r--r--internal/service/repository/redirecting_test_server_test.go2
-rw-r--r--internal/service/repository/rename_test.go2
-rw-r--r--internal/testhelper/testdata/tmp/.gitignore2
-rw-r--r--internal/testhelper/testhelper.go15
5 files changed, 20 insertions, 9 deletions
diff --git a/internal/safe/file_writer_test.go b/internal/safe/file_writer_test.go
index 293debf24..ff64dd9e1 100644
--- a/internal/safe/file_writer_test.go
+++ b/internal/safe/file_writer_test.go
@@ -16,7 +16,7 @@ import (
)
func TestFile(t *testing.T) {
- dir, cleanup := testhelper.TempDir(t, "", t.Name())
+ dir, cleanup := testhelper.TempDir(t, t.Name())
defer cleanup()
filePath := filepath.Join(dir, "test_file_contents")
@@ -42,7 +42,7 @@ func TestFile(t *testing.T) {
}
func TestFileRace(t *testing.T) {
- dir, cleanup := testhelper.TempDir(t, "", t.Name())
+ dir, cleanup := testhelper.TempDir(t, t.Name())
defer cleanup()
filePath := filepath.Join(dir, "test_file_contents")
@@ -69,7 +69,7 @@ func TestFileRace(t *testing.T) {
}
func TestFileCloseBeforeCommit(t *testing.T) {
- dir, cleanup := testhelper.TempDir(t, "", t.Name())
+ dir, cleanup := testhelper.TempDir(t, t.Name())
defer cleanup()
dstPath := filepath.Join(dir, "safety_meow")
@@ -88,7 +88,7 @@ func TestFileCloseBeforeCommit(t *testing.T) {
}
func TestFileCommitBeforeClose(t *testing.T) {
- dir, cleanup := testhelper.TempDir(t, "", t.Name())
+ dir, cleanup := testhelper.TempDir(t, t.Name())
defer cleanup()
dstPath := filepath.Join(dir, "safety_meow")
diff --git a/internal/service/repository/redirecting_test_server_test.go b/internal/service/repository/redirecting_test_server_test.go
index 8369b835d..d9dee1840 100644
--- a/internal/service/repository/redirecting_test_server_test.go
+++ b/internal/service/repository/redirecting_test_server_test.go
@@ -38,7 +38,7 @@ func StartRedirectingTestServer() (*RedirectingTestServerState, *httptest.Server
}
func TestRedirectingServerRedirects(t *testing.T) {
- dir, cleanup := testhelper.TempDir(t, "", t.Name())
+ dir, cleanup := testhelper.TempDir(t, t.Name())
defer cleanup()
httpServerState, redirectingServer := StartRedirectingTestServer()
diff --git a/internal/service/repository/rename_test.go b/internal/service/repository/rename_test.go
index 0b98259f0..70c8c8ea7 100644
--- a/internal/service/repository/rename_test.go
+++ b/internal/service/repository/rename_test.go
@@ -21,7 +21,7 @@ func TestRenameRepositorySuccess(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- tempDir, cleanupTempDir := testhelper.TempDir(t, "", t.Name())
+ tempDir, cleanupTempDir := testhelper.TempDir(t, t.Name())
defer cleanupTempDir()
destinationPath := filepath.Join(tempDir, "a", "new", "location")
diff --git a/internal/testhelper/testdata/tmp/.gitignore b/internal/testhelper/testdata/tmp/.gitignore
new file mode 100644
index 000000000..d6b7ef32c
--- /dev/null
+++ b/internal/testhelper/testdata/tmp/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index b18070fc1..c97dcfc3b 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -522,9 +522,18 @@ func CreateLooseRef(t *testing.T, repoPath, refName string) {
require.FileExists(t, filepath.Join(repoPath, relRefPath), "ref must be in loose file")
}
-// TempDir is a wrapper around ioutil.TempDir that provides a cleanup function
-func TempDir(t *testing.T, dir, prefix string) (string, func() error) {
- dirPath, err := ioutil.TempDir(dir, prefix)
+// TempDir is a wrapper around ioutil.TempDir that provides a cleanup function.
+// The returned temp directory will be created in the directory specified by
+// environment variable TEST_TEMP_DIR_PATH. If that variable is unset, the
+// relative folder "./testdata/tmp" to this source file will be used.
+func TempDir(t *testing.T, prefix string) (string, func() error) {
+ _, currentFile, _, ok := runtime.Caller(0)
+ if !ok {
+ log.Fatal("Could not get caller info")
+ }
+
+ rootTmpDir := path.Join(path.Dir(currentFile), "testdata/tmp")
+ dirPath, err := ioutil.TempDir(rootTmpDir, prefix)
require.NoError(t, err)
return dirPath, func() error {
return os.RemoveAll(dirPath)