Switch to "T.TempDir()" to avoid manual cleanup.

This commit is contained in:
Joachim Bauch 2022-04-05 12:40:26 +02:00
parent b98a00ec10
commit 9c2df744c1
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02

View file

@ -27,7 +27,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"time" "time"
@ -43,16 +42,12 @@ const (
) )
func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, func()) { func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, func()) {
tempdir, err := ioutil.TempDir("", "test") tempdir := t.TempDir()
if err != nil {
t.Fatalf("could not create temporary folder: %s", err)
}
var server *ProxyServer var server *ProxyServer
shutdown := func() { shutdown := func() {
if server != nil { if server != nil {
server.Stop() server.Stop()
} }
os.RemoveAll(tempdir)
} }
r := mux.NewRouter() r := mux.NewRouter()