From d3426c8379c9f31c585279987ca8b8d1791fdf84 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 19 Apr 2024 11:32:50 -0300 Subject: [PATCH] [NEW!!!] Only stop proservices if err is nil It'd be safe today to do so, but might not be tomorrow. The good practice is always to not touch the returned object if err is not nil. --- windows-agent/internal/proservices/proservices_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/windows-agent/internal/proservices/proservices_test.go b/windows-agent/internal/proservices/proservices_test.go index 27f808027..051433cd6 100644 --- a/windows-agent/internal/proservices/proservices_test.go +++ b/windows-agent/internal/proservices/proservices_test.go @@ -83,7 +83,9 @@ func TestNew(t *testing.T) { } s, err := proservices.New(ctx, publicDir, privateDir, proservices.WithRegistry(reg)) - defer s.Stop(ctx) + if err == nil { + defer s.Stop(ctx) + } if tc.wantErr { require.Error(t, err, "New should return an error") return