| 174 | } |
| 175 | |
| 176 | func TestRemoveTempFiles(t *testing.T) { |
| 177 | tmp, err := os.CreateTemp("", "excelize-*") |
| 178 | if err != nil { |
| 179 | t.Fatal(err) |
| 180 | } |
| 181 | tmpName := tmp.Name() |
| 182 | tmp.Close() |
| 183 | f := NewFile() |
| 184 | // fill the tempFiles map with non-existing (erroring on Remove) "files" |
| 185 | for i := 0; i < 1000; i++ { |
| 186 | f.tempFiles.Store(strconv.Itoa(i), "/hopefully not existing") |
| 187 | } |
| 188 | f.tempFiles.Store("existing", tmpName) |
| 189 | |
| 190 | require.Error(t, f.Close()) |
| 191 | if _, err := os.Stat(tmpName); err == nil { |
| 192 | t.Errorf("temp file %q still exist", tmpName) |
| 193 | os.Remove(tmpName) |
| 194 | } |
| 195 | } |