owrt/uci_firewall_redirect_test.go

84 lines
2.0 KiB
Go
Raw Normal View History

2018-11-07 11:50:59 +01:00
package owrt
import (
"testing"
)
const (
redirectName = "Test"
redirectIndex = -1
redirectSrc = "10.10.10.10/24"
redirectTarget = "ACCEPT"
redirectProto = "tcp"
redirectSrcDIP = "1.1.1.1"
redirectSrcDPort = "333"
redirectDestIP = "10.10.10.10"
redirectDestPort = "22"
)
func TestFWRedirectCreate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
redirect := NewUCIFirewallRedirect()
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Create(uci).ReturnCode != 0 {
t.Fatalf("UCIFirewallRedirect.Create() failed !")
}
}
func TestFWRedirectUpdate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
redirect := NewUCIFirewallRedirect()
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Create(uci).ReturnCode != 0 {
t.Fatalf("UCIFirewallRedirect.Create() failed !")
}
redirect.Name = "Tutu"
if redirect.Update(uci).ReturnCode != 0 {
t.Fatalf("UCIFirewallRedirect.Update() failed !")
}
}
func TestFWRedirectDelete(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
redirect := NewUCIFirewallRedirect()
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Delete(uci).ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Delete() failed !")
}
}