From 0177ebf4b031d52a897cf785c93d4780138e075e Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Mon, 21 Jun 2021 10:36:33 +1000 Subject: Use t.Cleanup --- test/acceptance/artifacts_test.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/acceptance/artifacts_test.go b/test/acceptance/artifacts_test.go index 476c67c1..d00ef516 100644 --- a/test/acceptance/artifacts_test.go +++ b/test/acceptance/artifacts_test.go @@ -17,10 +17,7 @@ import ( func TestArtifactProxyRequest(t *testing.T) { skipUnlessEnabled(t, "not-inplace-chroot") - transport := (TestHTTPSClient.Transport).(*http.Transport) - defer func(t time.Duration) { - transport.ResponseHeaderTimeout = t - }(transport.ResponseHeaderTimeout) + transport := (TestHTTPSClient.Transport).(*http.Transport).Clone() transport.ResponseHeaderTimeout = 5 * time.Second content := "Title of the document" @@ -49,12 +46,15 @@ func TestArtifactProxyRequest(t *testing.T) { keyFile, certFile := CreateHTTPSFixtureFiles(t) cert, err := tls.LoadX509KeyPair(certFile, keyFile) require.NoError(t, err) - defer os.Remove(keyFile) - defer os.Remove(certFile) testServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} testServer.StartTLS() - defer testServer.Close() + + t.Cleanup(func() { + os.Remove(keyFile) + os.Remove(certFile) + testServer.Close() + }) tests := []struct { name string @@ -170,15 +170,16 @@ func TestPrivateArtifactProxyRequest(t *testing.T) { keyFile, certFile := CreateHTTPSFixtureFiles(t) cert, err := tls.LoadX509KeyPair(certFile, keyFile) require.NoError(t, err) + + testServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} + testServer.StartTLS() + t.Cleanup(func() { os.Remove(keyFile) os.Remove(certFile) + testServer.Close() }) - testServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} - testServer.StartTLS() - defer testServer.Close() - tests := []struct { name string host string -- cgit v1.2.3