Use dedent to fix GetChainLines() tests

The test was calling GetChainLines() on invalid pseudo-iptables-save
output where most of the lines were indented. GetChainLines() happened
to still parse this "correctly", but it would be better to be testing
it on actually-correct data.
This commit is contained in:
Dan Winship 2022-06-01 10:55:15 -04:00
parent a3556edba1
commit 4988699c2f

View File

@ -18,6 +18,8 @@ package iptables
import (
"testing"
"github.com/lithammer/dedent"
)
func TestReadLinesFromByteBuffer(t *testing.T) {
@ -67,14 +69,15 @@ func checkAllLines(t *testing.T, table Table, save []byte, expectedLines map[Cha
}
func TestGetChainLines(t *testing.T) {
iptablesSave := `# Generated by iptables-save v1.4.7 on Wed Oct 29 14:56:01 2014
iptablesSave := dedent.Dedent(
`# Generated by iptables-save v1.4.7 on Wed Oct 29 14:56:01 2014
*nat
:PREROUTING ACCEPT [2136997:197881818]
:POSTROUTING ACCEPT [4284525:258542680]
:OUTPUT ACCEPT [5901660:357267963]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
COMMIT
# Completed on Wed Oct 29 14:56:01 2014`
# Completed on Wed Oct 29 14:56:01 2014`)
expected := map[Chain]string{
ChainPrerouting: ":PREROUTING ACCEPT [2136997:197881818]",
ChainPostrouting: ":POSTROUTING ACCEPT [4284525:258542680]",
@ -84,7 +87,8 @@ func TestGetChainLines(t *testing.T) {
}
func TestGetChainLinesMultipleTables(t *testing.T) {
iptablesSave := `# Generated by iptables-save v1.4.21 on Fri Aug 7 14:47:37 2015
iptablesSave := dedent.Dedent(
`# Generated by iptables-save v1.4.21 on Fri Aug 7 14:47:37 2015
*nat
:PREROUTING ACCEPT [2:138]
:INPUT ACCEPT [0:0]
@ -134,7 +138,7 @@ func TestGetChainLinesMultipleTables(t *testing.T) {
-A FORWARD -i cbr0 ! -o cbr0 -j ACCEPT
-A FORWARD -i cbr0 -o cbr0 -j ACCEPT
COMMIT
`
`)
expected := map[Chain]string{
ChainPrerouting: ":PREROUTING ACCEPT [2:138]",
Chain("INPUT"): ":INPUT ACCEPT [0:0]",