owrt/uci_network_interface_test.go

80 lines
1.6 KiB
Go
Raw Normal View History

package owrt
import (
"testing"
)
const (
ifName = "cadoles"
ifProto = "static"
ifIFName = "cdl-fake"
ifIPAddr = "192.168.59.1"
ifNetmask = "255.255.255.0"
ifDNS = "192.168.59.1"
ifIFType = "bridge"
ifMetric = "9000"
)
func TestNetCreate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
iface := NewUCINetworkInterface(uci)
iface.Name = ifName
iface.Proto = ifProto
iface.IFName = ifIFName
iface.IPAddr = ifIPAddr
iface.Netmask = ifNetmask
iface.DNS = ifDNS
iface.IFType = ifIFType
iface.Metric = ifMetric
if iface.Create().ReturnCode != 0 {
t.Fatalf("UCINetworkInterface.Create() failed !")
}
}
func TestNetUpdate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
iface := NewUCINetworkInterface(uci)
iface.Name = ifName
iface.Proto = ifProto
iface.IFName = ifIFName
iface.IPAddr = ifIPAddr
iface.Netmask = ifNetmask
iface.DNS = ifDNS
iface.IFType = ifIFType
iface.Metric = ifMetric
if iface.Create().ReturnCode != 0 {
t.Fatalf("UCINetworkInterface.Create() failed !")
}
iface.Metric = "1000"
if iface.Update().ReturnCode != 0 {
t.Fatalf("UCINetworkInterface.Update() failed !")
}
}
func TestNetDelete(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
iface := NewUCINetworkInterface(uci)
iface.Name = ifName
iface.Proto = ifProto
iface.IFName = ifIFName
iface.IPAddr = ifIPAddr
iface.Netmask = ifNetmask
iface.DNS = ifDNS
iface.IFType = ifIFType
iface.Metric = ifMetric
if iface.Delete().ReturnCode != 0 {
t.Fatalf("UCINetworkInterface.Delete() failed !")
}
}