kube-router/pkg/utils/iptables_test.go
qbnit 55b830d8f1 test: update utils/iptables_test to align with recent fix
Update tests for code affected in 8dfb5728582771dd6dd0341d3d0a122f14080cd5.
2024-08-06 16:51:21 -05:00

47 lines
1.5 KiB
Go

package utils
import (
"testing"
"github.com/stretchr/testify/assert"
v1core "k8s.io/api/core/v1"
)
func TestCommonICMPRules(t *testing.T) {
tests := []struct {
name string
family v1core.IPFamily
expected []ICMPRule
}{
{
name: "IPv4",
family: v1core.IPv4Protocol,
expected: []ICMPRule{
{"icmp", "--icmp-type", "echo-request", "allow icmp echo requests"},
{"icmp", "--icmp-type", "destination-unreachable", "allow icmp destination unreachable messages"},
{"icmp", "--icmp-type", "time-exceeded", "allow icmp time exceeded messages"},
},
},
{
name: "IPv6",
family: v1core.IPv6Protocol,
expected: []ICMPRule{
{"ipv6-icmp", "--icmpv6-type", "echo-request", "allow icmp echo requests"},
{"ipv6-icmp", "--icmpv6-type", "destination-unreachable", "allow icmp destination unreachable messages"},
{"ipv6-icmp", "--icmpv6-type", "time-exceeded", "allow icmp time exceeded messages"},
{"ipv6-icmp", "--icmpv6-type", "neighbor-solicitation", "allow icmp neighbor solicitation messages"},
{"ipv6-icmp", "--icmpv6-type", "neighbor-advertisement", "allow icmp neighbor advertisement messages"},
{"ipv6-icmp", "--icmpv6-type", "echo-reply", "allow icmp echo reply messages"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := CommonICMPRules(tt.family)
assert.Equal(t, tt.expected, result, "CommonICMPRules(%v) = %v, want %v", tt.family, result, tt.expected)
})
}
}