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

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-10-08 23:04:00 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2022-01-24 17:39:46 +0300
commit3c8b844011a8a7cf18c7589900ba7f12b2ebf570 (patch)
tree925d6dbeafb06f18a045d0574b8c4487f79797a7 /internal
parent136471e8d5a582236fb0f9565da3b0114a048b1e (diff)
test: replace tmpdir workaround with native T tmp
Diffstat (limited to 'internal')
-rw-r--r--internal/redirects/redirects_benchmark_test.go4
-rw-r--r--internal/redirects/redirects_test.go4
-rw-r--r--internal/serving/disk/symlink/path_test.go6
-rw-r--r--internal/testhelpers/tmpdir.go11
-rw-r--r--internal/vfs/local/root_test.go3
-rw-r--r--internal/vfs/local/vfs_test.go13
6 files changed, 16 insertions, 25 deletions
diff --git a/internal/redirects/redirects_benchmark_test.go b/internal/redirects/redirects_benchmark_test.go
index 1e679785..f02eb679 100644
--- a/internal/redirects/redirects_benchmark_test.go
+++ b/internal/redirects/redirects_benchmark_test.go
@@ -31,7 +31,7 @@ func generateRedirectsFile(dirPath string, count int) error {
func benchmarkRedirectsRewrite(b *testing.B, redirectsCount int) {
ctx := context.Background()
- root, tmpDir := testhelpers.TmpDir(b, "ParseRedirects_benchmarks")
+ root, tmpDir := testhelpers.TmpDir(b)
err := generateRedirectsFile(tmpDir, redirectsCount)
require.NoError(b, err)
@@ -65,7 +65,7 @@ func BenchmarkRedirectsRewrite_PlaceholdersEnabled(b *testing.B) {
func benchmarkRedirectsParseRedirects(b *testing.B, redirectsCount int) {
ctx := context.Background()
- root, tmpDir := testhelpers.TmpDir(b, "ParseRedirects_benchmarks")
+ root, tmpDir := testhelpers.TmpDir(b)
err := generateRedirectsFile(tmpDir, redirectsCount)
require.NoError(b, err)
diff --git a/internal/redirects/redirects_test.go b/internal/redirects/redirects_test.go
index b51043f7..5fdf8325 100644
--- a/internal/redirects/redirects_test.go
+++ b/internal/redirects/redirects_test.go
@@ -157,7 +157,7 @@ func TestRedirectsRewrite(t *testing.T) {
func TestRedirectsParseRedirects(t *testing.T) {
ctx := context.Background()
- root, tmpDir := testhelpers.TmpDir(t, "ParseRedirects_tests")
+ root, tmpDir := testhelpers.TmpDir(t)
tests := []struct {
name string
@@ -220,7 +220,7 @@ func TestRedirectsParseRedirects(t *testing.T) {
}
func TestMaxRuleCount(t *testing.T) {
- root, tmpDir := testhelpers.TmpDir(t, "TooManyRules_tests")
+ root, tmpDir := testhelpers.TmpDir(t)
err := os.WriteFile(path.Join(tmpDir, ConfigFile), []byte(strings.Repeat("/goto.html /target.html 301\n", maxRuleCount-1)+
"/1000.html /target1000 301\n"+
diff --git a/internal/serving/disk/symlink/path_test.go b/internal/serving/disk/symlink/path_test.go
index 59cb685f..10957a36 100644
--- a/internal/serving/disk/symlink/path_test.go
+++ b/internal/serving/disk/symlink/path_test.go
@@ -86,7 +86,7 @@ func testEvalSymlinks(t *testing.T, wd, path, want string) {
}
func TestEvalSymlinks(t *testing.T) {
- _, tmpDir := testhelpers.TmpDir(t, "symlink_tests")
+ _, tmpDir := testhelpers.TmpDir(t)
// Create the symlink farm using relative paths.
for _, d := range EvalSymlinksTestDirs {
@@ -124,7 +124,7 @@ func TestEvalSymlinks(t *testing.T) {
}
func TestEvalSymlinksIsNotExist(t *testing.T) {
- root, _ := testhelpers.TmpDir(t, "symlink_tests")
+ root, _ := testhelpers.TmpDir(t)
_, err := symlink.EvalSymlinks(context.Background(), root, "notexist")
if !errors.Is(err, fs.ErrNotExist) {
@@ -144,7 +144,7 @@ func TestEvalSymlinksIsNotExist(t *testing.T) {
}
func TestIssue13582(t *testing.T) {
- root, tmpDir := testhelpers.TmpDir(t, "symlink_tests")
+ root, tmpDir := testhelpers.TmpDir(t)
dir := filepath.Join(tmpDir, "dir")
err := os.Mkdir(dir, 0755)
diff --git a/internal/testhelpers/tmpdir.go b/internal/testhelpers/tmpdir.go
index de104a04..d5d4d165 100644
--- a/internal/testhelpers/tmpdir.go
+++ b/internal/testhelpers/tmpdir.go
@@ -2,7 +2,6 @@ package testhelpers
import (
"context"
- "os"
"path/filepath"
"testing"
@@ -14,11 +13,11 @@ import (
var fs = vfs.Instrumented(&local.VFS{})
-func TmpDir(tb testing.TB, pattern string) (vfs.Root, string) {
+func TmpDir(tb testing.TB) (vfs.Root, string) {
tb.Helper()
- tmpDir, err := os.MkdirTemp("", pattern)
- require.NoError(tb, err)
+ var err error
+ tmpDir := tb.TempDir()
// On some systems `/tmp` can be a symlink
tmpDir, err = filepath.EvalSymlinks(tmpDir)
@@ -27,9 +26,5 @@ func TmpDir(tb testing.TB, pattern string) (vfs.Root, string) {
root, err := fs.Root(context.Background(), tmpDir, "")
require.NoError(tb, err)
- tb.Cleanup(func() {
- require.NoError(tb, os.RemoveAll(tmpDir))
- })
-
return root, tmpDir
}
diff --git a/internal/vfs/local/root_test.go b/internal/vfs/local/root_test.go
index e7bbb63f..094a48c0 100644
--- a/internal/vfs/local/root_test.go
+++ b/internal/vfs/local/root_test.go
@@ -123,8 +123,7 @@ func TestReadlinkAbsolutePath(t *testing.T) {
// /tmp/dir: directory
// /tmp/dir/symlink: points to `/tmp/file` outside of the `/tmp/dir`
// /tmp/dir/symlink2: points to `/tmp/dir/file`
- tmpDir, cleanup := tmpDir(t)
- defer cleanup()
+ tmpDir := tmpDir(t)
dirPath := filepath.Join(tmpDir, "dir")
err := os.Mkdir(dirPath, 0755)
diff --git a/internal/vfs/local/vfs_test.go b/internal/vfs/local/vfs_test.go
index e9b3fe71..fd36dd4c 100644
--- a/internal/vfs/local/vfs_test.go
+++ b/internal/vfs/local/vfs_test.go
@@ -14,17 +14,15 @@ import (
var localVFS = &VFS{}
-func tmpDir(t *testing.T) (string, func()) {
- tmpDir, err := os.MkdirTemp("", "vfs")
- require.NoError(t, err)
+func tmpDir(t *testing.T) string {
+ var err error
+ tmpDir := t.TempDir()
// On some systems `/tmp` can be a symlink
tmpDir, err = filepath.EvalSymlinks(tmpDir)
require.NoError(t, err)
- return tmpDir, func() {
- os.RemoveAll(tmpDir)
- }
+ return tmpDir
}
func TestVFSRoot(t *testing.T) {
@@ -35,8 +33,7 @@ func TestVFSRoot(t *testing.T) {
// /tmp/file: file
// /tmp/file_link: symlink to `file`
// /tmp/file_absolute_link: symlink to `/tmp/file`
- tmpDir, cleanup := tmpDir(t)
- defer cleanup()
+ tmpDir := tmpDir(t)
dirPath := filepath.Join(tmpDir, "dir")
err := os.Mkdir(dirPath, 0755)