diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-10-08 23:04:00 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-24 17:39:46 +0300 |
commit | 3c8b844011a8a7cf18c7589900ba7f12b2ebf570 (patch) | |
tree | 925d6dbeafb06f18a045d0574b8c4487f79797a7 /test/acceptance | |
parent | 136471e8d5a582236fb0f9565da3b0114a048b1e (diff) |
test: replace tmpdir workaround with native T tmp
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/artifacts_test.go | 5 | ||||
-rw-r--r-- | test/acceptance/auth_test.go | 8 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go | 24 | ||||
-rw-r--r-- | test/acceptance/stub_test.go | 6 |
4 files changed, 10 insertions, 33 deletions
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() |