Fix use of "-w" flag to iptables-restore

iptables accepts "-w5" but iptables-restore requires "-w 5"
This commit is contained in:
Dan Winship
2018-03-09 08:49:52 -05:00
parent 8d02b2b39a
commit 34ce573e99
2 changed files with 20 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"net"
"os"
"reflect"
"strings"
"testing"
"time"
@@ -681,21 +682,21 @@ COMMIT
func TestIPTablesWaitFlag(t *testing.T) {
testCases := []struct {
Version string
Result string
Result []string
}{
{"0.55.55", ""},
{"1.0.55", ""},
{"1.4.19", ""},
{"1.4.20", WaitString},
{"1.4.21", WaitString},
{"1.4.22", WaitSecondsString},
{"1.5.0", WaitSecondsString},
{"2.0.0", WaitSecondsString},
{"0.55.55", nil},
{"1.0.55", nil},
{"1.4.19", nil},
{"1.4.20", []string{WaitString}},
{"1.4.21", []string{WaitString}},
{"1.4.22", []string{WaitString, WaitSecondsValue}},
{"1.5.0", []string{WaitString, WaitSecondsValue}},
{"2.0.0", []string{WaitString, WaitSecondsValue}},
}
for _, testCase := range testCases {
result := getIPTablesWaitFlag(testCase.Version)
if strings.Join(result, "") != testCase.Result {
if !reflect.DeepEqual(result, testCase.Result) {
t.Errorf("For %s expected %v got %v", testCase.Version, testCase.Result, result)
}
}
@@ -730,7 +731,7 @@ func TestWaitFlagUnavailable(t *testing.T) {
if fcmd.CombinedOutputCalls != 3 {
t.Errorf("expected 3 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
}
if sets.NewString(fcmd.CombinedOutputLog[2]...).HasAny(WaitString, WaitSecondsString) {
if sets.NewString(fcmd.CombinedOutputLog[2]...).Has(WaitString) {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
}
@@ -765,7 +766,7 @@ func TestWaitFlagOld(t *testing.T) {
if !sets.NewString(fcmd.CombinedOutputLog[2]...).HasAll("iptables", WaitString) {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
if sets.NewString(fcmd.CombinedOutputLog[2]...).HasAny(WaitSecondsString) {
if sets.NewString(fcmd.CombinedOutputLog[2]...).Has(WaitSecondsValue) {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
}
@@ -797,10 +798,7 @@ func TestWaitFlagNew(t *testing.T) {
if fcmd.CombinedOutputCalls != 3 {
t.Errorf("expected 3 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
}
if !sets.NewString(fcmd.CombinedOutputLog[2]...).HasAll("iptables", WaitSecondsString) {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
if sets.NewString(fcmd.CombinedOutputLog[2]...).HasAny(WaitString) {
if !sets.NewString(fcmd.CombinedOutputLog[2]...).HasAll("iptables", WaitString, WaitSecondsValue) {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
}
@@ -1165,7 +1163,7 @@ func TestRestoreAllWait(t *testing.T) {
}
commandSet := sets.NewString(fcmd.CombinedOutputLog[2]...)
if !commandSet.HasAll("iptables-restore", WaitSecondsString, "--counters", "--noflush") {
if !commandSet.HasAll("iptables-restore", WaitString, WaitSecondsValue, "--counters", "--noflush") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
@@ -1214,8 +1212,8 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) {
if !commandSet.HasAll("iptables-restore", "--counters", "--noflush") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2])
}
if commandSet.HasAny(WaitSecondsString) {
t.Errorf("wrong CombinedOutput() log (unexpected %s option), got %s", WaitSecondsString, fcmd.CombinedOutputLog[2])
if commandSet.HasAll(WaitString, WaitSecondsValue) {
t.Errorf("wrong CombinedOutput() log (unexpected %s option), got %s", WaitString, fcmd.CombinedOutputLog[2])
}
if fcmd.CombinedOutputCalls != 3 {