Commit 65122c6f authored by Shijun Qin's avatar Shijun Qin Committed by qinshijun

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.
parent b8c5bcf4
...@@ -149,7 +149,6 @@ func TestConfigDirCleaner(t *testing.T) { ...@@ -149,7 +149,6 @@ func TestConfigDirCleaner(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %s", err) t.Errorf("Unable to create temporary directory: %s", err)
} }
defer os.RemoveAll(tmpDir)
for _, createDir := range test.setupDirs { for _, createDir := range test.setupDirs {
err := os.Mkdir(filepath.Join(tmpDir, createDir), 0700) err := os.Mkdir(filepath.Join(tmpDir, createDir), 0700)
...@@ -164,7 +163,7 @@ func TestConfigDirCleaner(t *testing.T) { ...@@ -164,7 +163,7 @@ func TestConfigDirCleaner(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unable to create test file: %s", err) t.Errorf("Unable to create test file: %s", err)
} }
defer f.Close() f.Close()
} }
resetConfigDir(tmpDir, filepath.Join(tmpDir, "pki")) resetConfigDir(tmpDir, filepath.Join(tmpDir, "pki"))
...@@ -183,6 +182,8 @@ func TestConfigDirCleaner(t *testing.T) { ...@@ -183,6 +182,8 @@ func TestConfigDirCleaner(t *testing.T) {
for _, path := range test.verifyNotExists { for _, path := range test.verifyNotExists {
assertNotExists(t, filepath.Join(tmpDir, path)) assertNotExists(t, filepath.Join(tmpDir, path))
} }
os.RemoveAll(tmpDir)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment