Merge pull request #98961 from aojea/donotleak

Do not leak files on iptables unit tests
This commit is contained in:
Kubernetes Prow Robot 2021-02-11 01:48:23 -08:00 committed by GitHub
commit 63f89493ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1025,6 +1025,9 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) {
},
}
lockPath14x, lockPath16x := getLockPaths()
// the lockPath14x is a UNIX socket which is cleaned up automatically on close, but the
// lockPath16x is a plain file which is not cleaned up.
defer os.Remove(lockPath16x)
runner := newInternal(&fexec, ProtocolIPv4, lockPath14x, lockPath16x)
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
@ -1077,7 +1080,10 @@ func TestRestoreAllGrabNewLock(t *testing.T) {
if err != nil {
t.Fatalf("expected to open %s, got %v", lockPath16x, err)
}
defer runLock.Close()
defer func() {
runLock.Close()
os.Remove(lockPath16x)
}()
if err := grabIptablesFileLock(runLock); err != nil {
t.Errorf("expected to lock %s, got %v", lockPath16x, err)
@ -1111,6 +1117,9 @@ func TestRestoreAllGrabOldLock(t *testing.T) {
},
}
lockPath14x, lockPath16x := getLockPaths()
// the lockPath14x is a UNIX socket which is cleaned up automatically on close, but the
// lockPath16x is a plain file which is not cleaned up.
defer os.Remove(lockPath16x)
runner := newInternal(&fexec, ProtocolIPv4, lockPath14x, lockPath16x)
var runLock *net.UnixListener