From 6877b8067fe451ed68d48acea2ebcb984c83eacf Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 May 2024 15:45:03 -0500 Subject: [PATCH] Use t.Cleanup() rather than defer to shutdown test servers Thanks @phillebaba! --- src/pkg/packager/sources/new_test.go | 2 +- src/pkg/utils/network_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/packager/sources/new_test.go b/src/pkg/packager/sources/new_test.go index 1087764d4a..91ea3e2c2f 100644 --- a/src/pkg/packager/sources/new_test.go +++ b/src/pkg/packager/sources/new_test.go @@ -130,7 +130,7 @@ func TestPackageSource(t *testing.T) { defer f.Close() io.Copy(rw, f) })) - defer ts.Close() + t.Cleanup(func() { ts.Close() }) tests := []struct { name string diff --git a/src/pkg/utils/network_test.go b/src/pkg/utils/network_test.go index 84ec01b623..1728fe874b 100644 --- a/src/pkg/utils/network_test.go +++ b/src/pkg/utils/network_test.go @@ -85,7 +85,7 @@ func TestDownloadToFile(t *testing.T) { } rw.Write([]byte(content)) })) - defer srv.Close() + t.Cleanup(func() { srv.Close() }) tests := []struct { name string