owrt/uci_firewall_rules_test.go

76 lines
1.6 KiB
Go
Raw Normal View History

2018-11-07 11:50:59 +01:00
package owrt
import (
"testing"
)
const (
ruleName = "Test"
ruleIndex = -1
ruleSrc = "10.10.10.10/24"
ruleTarget = "ACCEPT"
ruleProto = "tcp"
ruleDestPort = "80"
ruleSourcePort = "8080"
)
func TestFWRuleCreate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
rule := NewUCIFirewallRule(uci)
2018-11-07 11:50:59 +01:00
rule.Name = ruleName
rule.Index = ruleIndex
rule.Src = ruleSrc
rule.Target = ruleTarget
rule.Proto = ruleProto
rule.DestPort = ruleDestPort
rule.SourcePort = ruleSourcePort
if rule.Create().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRule.Create() failed !")
}
}
func TestFWRuleUpdate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
rule := NewUCIFirewallRule(uci)
2018-11-07 11:50:59 +01:00
rule.Name = ruleName
rule.Index = ruleIndex
rule.Src = ruleSrc
rule.Target = ruleTarget
rule.Proto = ruleProto
rule.DestPort = ruleDestPort
rule.SourcePort = ruleSourcePort
if rule.Create().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRule.Create() failed !")
}
rule.Name = "Tutu"
if rule.Update().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRule.Update() failed !")
}
}
func TestFWRuleDelete(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
rule := NewUCIFirewallRule(uci)
2018-11-07 11:50:59 +01:00
rule.Name = ruleName
rule.Index = ruleIndex
rule.Src = ruleSrc
rule.Target = ruleTarget
rule.Proto = ruleProto
rule.DestPort = ruleDestPort
rule.SourcePort = ruleSourcePort
if rule.Delete().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIWirelessInterface.Delete() failed !")
}
}