Fix: remove keyword defer in the loop

Appearance of defer keyword inside a loop structure may caused resource leaks, it's not recommended to do it although it is in an unit test. Releasing a resource just after finishing using it is the highest effective solution, so remove defer is just OK.
This commit is contained in:
Shijun Qin 2018-02-28 20:17:56 +08:00 committed by qinshijun
parent b8c5bcf48a
commit 65122c6f05

View File

@ -149,7 +149,6 @@ func TestConfigDirCleaner(t *testing.T) {
if err != nil {
t.Errorf("Unable to create temporary directory: %s", err)
}
defer os.RemoveAll(tmpDir)
for _, createDir := range test.setupDirs {
err := os.Mkdir(filepath.Join(tmpDir, createDir), 0700)
@ -164,7 +163,7 @@ func TestConfigDirCleaner(t *testing.T) {
if err != nil {
t.Errorf("Unable to create test file: %s", err)
}
defer f.Close()
f.Close()
}
resetConfigDir(tmpDir, filepath.Join(tmpDir, "pki"))
@ -183,6 +182,8 @@ func TestConfigDirCleaner(t *testing.T) {
for _, path := range test.verifyNotExists {
assertNotExists(t, filepath.Join(tmpDir, path))
}
os.RemoveAll(tmpDir)
}
}