iptables_test.go 669 B

12345678910111213141516171819202122232425262728293031
  1. package firewall
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestBuildNATRuleLines_InterfaceList(t *testing.T) {
  7. rule := NATRule{
  8. ID: "nat-test-1",
  9. Order: 1,
  10. Chain: "srcnat",
  11. Action: "masquerade",
  12. OutInterfaceList: "WAN",
  13. Disabled: false,
  14. }
  15. lines := buildNATRuleLines(rule)
  16. if len(lines) == 0 {
  17. t.Fatalf("expected non-empty lines for WAN interface list, got 0")
  18. }
  19. for _, l := range lines {
  20. if !strings.Contains(l, "-j MASQUERADE") {
  21. t.Errorf("line missing -j MASQUERADE: %s", l)
  22. }
  23. if !strings.Contains(l, "-o ") {
  24. t.Errorf("expected -o flag in expanded NAT rule, got: %s", l)
  25. }
  26. }
  27. }