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
path: root/test
diff options
context:
space:
mode:
authorVladimir Shushlin <vshushlin@gitlab.com>2022-01-25 17:17:14 +0300
committerVladimir Shushlin <vshushlin@gitlab.com>2022-01-25 17:17:14 +0300
commitc27391b4ab52f19f0457550d50aff427c370f620 (patch)
tree25ad6eb46953132eb9a42a2002e0d8d990909a3b /test
parentfd42d1c1e640e20b0fe4f61a45b7179d04c74f11 (diff)
parent3c8b844011a8a7cf18c7589900ba7f12b2ebf570 (diff)
Merge branch 'refactor/test-tmp' into 'master'
test: replace tmpdir workaround with native T tmp See merge request gitlab-org/gitlab-pages!598
Diffstat (limited to 'test')
-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
4 files changed, 10 insertions, 33 deletions
diff --git a/test/acceptance/artifacts_test.go b/test/acceptance/artifacts_test.go
index 2545c77e..f087581c 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 b9cba467..62a5e344 100644
--- a/test/acceptance/helpers_test.go
+++ b/test/acceptance/helpers_test.go
@@ -254,11 +254,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,
@@ -268,10 +267,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()) {
@@ -283,7 +278,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
@@ -295,9 +290,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)
}()
@@ -318,7 +310,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")
@@ -332,7 +324,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)
}
@@ -563,7 +554,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()
@@ -586,11 +577,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 9e271f37..0fcdfa2e 100644
--- a/test/acceptance/stub_test.go
+++ b/test/acceptance/stub_test.go
@@ -69,12 +69,14 @@ func withStubOptions(opts *stubOpts) processOption {
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()