From 7fbc2a8c14d016dc5923efddc4f2a926d3486aea Mon Sep 17 00:00:00 2001 From: stk Date: Sat, 2 May 2026 17:49:18 +0200 Subject: [PATCH] Close temp file handles before cleanup on Windows Windows cannot remove files while handles are still open. In TestOSCommandFileType we created files and immediately called RemoveAll without closing handles, which left untracked artifacts (e.g. "testFile" and "file with spaces") in the working tree. Close the handles and assert RemoveAll succeeds so cleanup failures are visible. --- pkg/commands/oscommands/os_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index ecae92b18..54d9f3a80 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -91,7 +91,11 @@ func TestOSCommandFileType(t *testing.T) { { "testFile", func() { - if _, err := os.Create("testFile"); err != nil { + f, err := os.Create("testFile") + if err != nil { + panic(err) + } + if err := f.Close(); err != nil { panic(err) } }, @@ -102,7 +106,11 @@ func TestOSCommandFileType(t *testing.T) { { "file with spaces", func() { - if _, err := os.Create("file with spaces"); err != nil { + f, err := os.Create("file with spaces") + if err != nil { + panic(err) + } + if err := f.Close(); err != nil { panic(err) } }, @@ -133,7 +141,7 @@ func TestOSCommandFileType(t *testing.T) { for _, s := range scenarios { s.setup() s.test(FileType(s.path)) - _ = os.RemoveAll(s.path) + assert.NoError(t, os.RemoveAll(s.path)) } }