Преглед на файлове

Merge pull request #104 from bgilbert/tests

iptables_test: fix ListWithCounters mismatch on newer kernels to fix CI
Benjamin Gilbert преди 1 година
родител
ревизия
cca2130b78
променени са 2 файла, в които са добавени 16 реда и са изтрити 18 реда
  1. 15 17
      iptables/iptables_test.go
  2. 1 1
      test

+ 15 - 17
iptables/iptables_test.go

@@ -131,7 +131,7 @@ func runChainTests(t *testing.T, ipt *IPTables) {
 	chain := randChain(t)
 
 	// Saving the list of chains before executing tests
-	originaListChain, err := ipt.ListChains("filter")
+	originalListChain, err := ipt.ListChains("filter")
 	if err != nil {
 		t.Fatalf("ListChains of Initial failed: %v", err)
 	}
@@ -204,8 +204,8 @@ func runChainTests(t *testing.T, ipt *IPTables) {
 	if err != nil {
 		t.Fatalf("ListChains failed: %v", err)
 	}
-	if !reflect.DeepEqual(originaListChain, listChain) {
-		t.Fatalf("ListChains mismatch: \ngot  %#v \nneed %#v", originaListChain, listChain)
+	if !reflect.DeepEqual(originalListChain, listChain) {
+		t.Fatalf("ListChains mismatch: \ngot  %#v \nneed %#v", originalListChain, listChain)
 	}
 
 	// ChainExists must not find it anymore
@@ -336,21 +336,19 @@ func runRulesTests(t *testing.T, ipt *IPTables) {
 		t.Fatalf("ListWithCounters failed: %v", err)
 	}
 
-	suffix := " -c 0 0 -j ACCEPT"
-	if ipt.mode == "nf_tables" {
-		suffix = " -j ACCEPT -c 0 0"
-	}
-
-	expected = []string{
-		"-N " + chain,
-		"-A " + chain + " -s " + subnet1 + " -d " + address1 + suffix,
-		"-A " + chain + " -s " + subnet2 + " -d " + address2 + suffix,
-		"-A " + chain + " -s " + subnet2 + " -d " + address1 + suffix,
-		"-A " + chain + " -s " + address1 + " -d " + subnet2 + suffix,
+	makeExpected := func(suffix string) []string {
+		return []string{
+			"-N " + chain,
+			"-A " + chain + " -s " + subnet1 + " -d " + address1 + " " + suffix,
+			"-A " + chain + " -s " + subnet2 + " -d " + address2 + " " + suffix,
+			"-A " + chain + " -s " + subnet2 + " -d " + address1 + " " + suffix,
+			"-A " + chain + " -s " + address1 + " -d " + subnet2 + " " + suffix,
+		}
 	}
-
-	if !reflect.DeepEqual(rules, expected) {
-		t.Fatalf("ListWithCounters mismatch: \ngot  %#v \nneed %#v", rules, expected)
+	// older nf_tables returned the second order
+	if !reflect.DeepEqual(rules, makeExpected("-c 0 0 -j ACCEPT")) &&
+		!reflect.DeepEqual(rules, makeExpected("-j ACCEPT -c 0 0")) {
+		t.Fatalf("ListWithCounters mismatch: \ngot  %#v \nneed %#v", rules, makeExpected("<-c 0 0 and -j ACCEPT in either order>"))
 	}
 
 	stats, err := ipt.Stats("filter", chain)

+ 1 - 1
test

@@ -47,7 +47,7 @@ TEST=${split[@]/#/${REPO_PATH}/}
 echo "Running tests..."
 bin=$(mktemp)
 
-go test -c -o ${bin} ${COVER} -i ${TEST}
+go test -c -o ${bin} ${COVER} ${TEST}
 if [[ -z "$SUDO_PERMITTED" ]]; then
     echo "Test aborted for safety reasons. Please set the SUDO_PERMITTED variable."
     exit 1