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.
This commit is contained in:
stk 2026-05-02 17:49:18 +02:00 committed by Stefan Haller
parent 3ffc4ac832
commit 7fbc2a8c14

View file

@ -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))
}
}