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:
-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
-rw-r--r--test/acceptance/artifacts_test.go5
-rw-r--r--test/acceptance/auth_test.go8
-rw-r--r--test/acceptance/helpers_test.go24
-rw-r--r--test/acceptance/stub_test.go6
10 files changed, 26 insertions, 58 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)
diff --git a/test/acceptance/artifacts_test.go b/test/acceptance/artifacts_test.go
index dddfeb67..8bcbfd64 100644
--- a/test/acceptance/artifacts_test.go
+++ b/test/acceptance/artifacts_test.go
@@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
- "os"
"testing"
"time"
@@ -49,8 +48,6 @@ func TestArtifactProxyRequest(t *testing.T) {
testServer.StartTLS()
t.Cleanup(func() {
- os.Remove(keyFile)
- os.Remove(certFile)
testServer.Close()
})
@@ -165,8 +162,6 @@ func TestPrivateArtifactProxyRequest(t *testing.T) {
testServer.StartTLS()
t.Cleanup(func() {
- os.Remove(keyFile)
- os.Remove(certFile)
testServer.Close()
})
diff --git a/test/acceptance/auth_test.go b/test/acceptance/auth_test.go
index d115dba5..18b73161 100644
--- a/test/acceptance/auth_test.go
+++ b/test/acceptance/auth_test.go
@@ -5,7 +5,6 @@ import (
"io"
"net/http"
"net/url"
- "os"
"testing"
"github.com/stretchr/testify/require"
@@ -424,12 +423,7 @@ type runPagesFunc func(t *testing.T, listeners []ListenSpec, sslCertFile string)
func testAccessControl(t *testing.T, runPages runPagesFunc) {
setupTransport(t)
- keyFile, certFile := CreateHTTPSFixtureFiles(t)
-
- t.Cleanup(func() {
- os.Remove(keyFile)
- os.Remove(certFile)
- })
+ _, certFile := CreateHTTPSFixtureFiles(t)
tests := map[string]struct {
host string
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go
index d21df0a8..d1db8762 100644
--- a/test/acceptance/helpers_test.go
+++ b/test/acceptance/helpers_test.go
@@ -253,11 +253,10 @@ func RunPagesProcessWithSSLCertFile(t *testing.T, listeners []ListenSpec, sslCer
func RunPagesProcessWithSSLCertDir(t *testing.T, listeners []ListenSpec, sslCertFile string) {
// Create temporary cert dir
- sslCertDir, err := os.MkdirTemp("", "pages-test-SSL_CERT_DIR")
- require.NoError(t, err)
+ sslCertDir := t.TempDir()
// Copy sslCertFile into temp cert dir
- err = copyFile(sslCertDir+"/"+path.Base(sslCertFile), sslCertFile)
+ err := copyFile(sslCertDir+"/"+path.Base(sslCertFile), sslCertFile)
require.NoError(t, err)
RunPagesProcess(t,
@@ -267,10 +266,6 @@ func RunPagesProcessWithSSLCertDir(t *testing.T, listeners []ListenSpec, sslCert
}),
withEnv([]string{"SSL_CERT_DIR=" + sslCertDir}),
)
-
- t.Cleanup(func() {
- os.RemoveAll(sslCertDir)
- })
}
func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []ListenSpec, promPort string, extraEnv []string, extraArgs ...string) (*LogCaptureBuffer, func()) {
@@ -282,7 +277,7 @@ func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []Li
logBuf := &LogCaptureBuffer{}
out := io.MultiWriter(&tWriter{t}, logBuf)
- args, tempfiles := getPagesArgs(t, listeners, promPort, extraArgs)
+ args := getPagesArgs(t, listeners, promPort, extraArgs)
cmd := exec.Command(pagesBinary, args...)
cmd.Env = append(os.Environ(), extraEnv...)
cmd.Stdout = out
@@ -294,9 +289,6 @@ func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []Li
waitCh := make(chan struct{})
go func() {
require.NoError(t, cmd.Wait())
- for _, tempfile := range tempfiles {
- os.Remove(tempfile)
- }
close(waitCh)
}()
@@ -317,7 +309,7 @@ func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []Li
return logBuf, cleanup
}
-func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraArgs []string) (args, tempfiles []string) {
+func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraArgs []string) (args []string) {
var hasHTTPS bool
args = append(args, "-log-verbose=true")
@@ -331,7 +323,6 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr
if hasHTTPS {
key, cert := CreateHTTPSFixtureFiles(t)
- tempfiles = []string{key, cert}
args = append(args, "-root-key", key, "-root-cert", cert)
}
@@ -577,7 +568,7 @@ func defaultUserHandler(t *testing.T) http.HandlerFunc {
func newConfigFile(t *testing.T, configs ...string) string {
t.Helper()
- f, err := os.CreateTemp(os.TempDir(), "gitlab-pages-config")
+ f, err := os.CreateTemp(t.TempDir(), "gitlab-pages-config")
require.NoError(t, err)
defer f.Close()
@@ -600,11 +591,6 @@ func defaultConfigFileWith(t *testing.T, configs ...string) string {
name := newConfigFile(t, configs...)
- t.Cleanup(func() {
- err := os.Remove(name)
- require.NoError(t, err)
- })
-
return name
}
diff --git a/test/acceptance/stub_test.go b/test/acceptance/stub_test.go
index 7fc733a1..37ef0873 100644
--- a/test/acceptance/stub_test.go
+++ b/test/acceptance/stub_test.go
@@ -110,12 +110,14 @@ func apiHandler(t *testing.T) http.HandlerFunc {
func CreateHTTPSFixtureFiles(t *testing.T) (key string, cert string) {
t.Helper()
- keyfile, err := os.CreateTemp("", "https-fixture")
+ tmpDir := t.TempDir()
+
+ keyfile, err := os.CreateTemp(tmpDir, "https-fixture")
require.NoError(t, err)
key = keyfile.Name()
keyfile.Close()
- certfile, err := os.CreateTemp("", "https-fixture")
+ certfile, err := os.CreateTemp(tmpDir, "https-fixture")
require.NoError(t, err)
cert = certfile.Name()
certfile.Close()