2018-10-24 16:55:47 +02:00
|
|
|
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)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-10-24 16:55:47 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-10-25 10:24:45 +02:00
|
|
|
if iface.Create().ReturnCode != 0 {
|
2018-10-24 16:55:47 +02:00
|
|
|
t.Fatalf("UCINetworkInterface.Create() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetUpdate(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-10-24 16:55:47 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-10-25 10:24:45 +02:00
|
|
|
if iface.Create().ReturnCode != 0 {
|
2018-10-24 16:55:47 +02:00
|
|
|
t.Fatalf("UCINetworkInterface.Create() failed !")
|
|
|
|
}
|
|
|
|
|
|
|
|
iface.Metric = "1000"
|
|
|
|
|
2018-10-25 10:24:45 +02:00
|
|
|
if iface.Update().ReturnCode != 0 {
|
2018-10-24 16:55:47 +02:00
|
|
|
t.Fatalf("UCINetworkInterface.Update() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetDelete(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-10-24 16:55:47 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-10-25 10:24:45 +02:00
|
|
|
if iface.Delete().ReturnCode != 0 {
|
2018-10-24 16:55:47 +02:00
|
|
|
t.Fatalf("UCINetworkInterface.Delete() failed !")
|
|
|
|
}
|
|
|
|
}
|