don´t leak files on iptables tests

the iptables restore function, if it considers that the --wait flag
is not supported, creates a lock file to mimic the iptables behaviour.

The test should take this into account and remove the file.
This commit is contained in:
Antonio Ojea 2021-02-10 09:27:28 +01:00
parent 6b9379eae4
commit 7223f12f39

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