From 3e1c934f2ce3247352d014d178ea312a91802964 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Tue, 4 Jul 2023 12:31:17 +0200 Subject: [PATCH] Use cleanup function --- autocert/storage_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/autocert/storage_test.go b/autocert/storage_test.go index 4da4187a..d8dae70a 100644 --- a/autocert/storage_test.go +++ b/autocert/storage_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -func getCryptoStorage() certmagic.Storage { +func getCryptoStorage(t *testing.T) certmagic.Storage { s := &certmagic.FileStorage{ Path: "./testing", } @@ -18,12 +18,15 @@ func getCryptoStorage() certmagic.Storage { sc := NewCryptoStorage(s, c) + t.Cleanup(func() { + os.RemoveAll("./testing/") + }) + return sc } func TestFileStorageStoreLoad(t *testing.T) { - s := getCryptoStorage() - defer os.RemoveAll("./testing/") + s := getCryptoStorage(t) data := []byte("some data") ctx := context.Background() @@ -37,8 +40,7 @@ func TestFileStorageStoreLoad(t *testing.T) { } func TestFileStorageDelete(t *testing.T) { - s := getCryptoStorage() - defer os.RemoveAll("./testing/") + s := getCryptoStorage(t) data := []byte("some data") ctx := context.Background() @@ -57,8 +59,7 @@ func TestFileStorageDelete(t *testing.T) { } func TestFileStorageExists(t *testing.T) { - s := getCryptoStorage() - defer os.RemoveAll("./testing/") + s := getCryptoStorage(t) data := []byte("some data") ctx := context.Background() @@ -80,8 +81,7 @@ func TestFileStorageExists(t *testing.T) { } func TestFileStorageStat(t *testing.T) { - s := getCryptoStorage() - defer os.RemoveAll("./testing/") + s := getCryptoStorage(t) data := []byte("some data") ctx := context.Background()