103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
package owrt
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
ifNameDHCP = "cadoles"
|
|
ifProtoDHCP = "static"
|
|
ifIFNameDHCP = "cdl-fake"
|
|
ifIPAddrDHCP = "192.168.59.1"
|
|
ifNetmaskDHCP = "255.255.255.0"
|
|
ifDNSDHCP = "192.168.59.1"
|
|
ifIFTypeDHCP = "bridge"
|
|
ifLeaseTimeDHCP = "4h"
|
|
ifMetricDHCP = "9000"
|
|
ifRangeLimitDHCP = "10"
|
|
ifStartIPDHCP = "192.168.59.10"
|
|
)
|
|
|
|
func TestNetCreateWithDHCP(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
iface := NewUCINetworkInterface(uci)
|
|
iface.Name = ifNameDHCP
|
|
iface.Proto = ifProtoDHCP
|
|
iface.IFName = ifIFNameDHCP
|
|
iface.IPAddr = ifIPAddrDHCP
|
|
iface.Netmask = ifNetmaskDHCP
|
|
iface.DNS = ifDNSDHCP
|
|
iface.IFType = ifIFTypeDHCP
|
|
iface.Metric = ifMetricDHCP
|
|
iface.DHCP.Name = ifNameDHCP
|
|
iface.DHCP.IFName = ifIFNameDHCP
|
|
iface.DHCP.LeaseTime = ifLeaseTimeDHCP
|
|
iface.DHCP.RangeLimit = ifRangeLimitDHCP
|
|
iface.DHCP.StartIP = ifStartIPDHCP
|
|
|
|
if iface.Create().ReturnCode != 0 {
|
|
t.Fatalf("UCINetworkInterface.Create() failed !")
|
|
}
|
|
}
|
|
|
|
func TestNetUpdateWithDHCP(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
iface := NewUCINetworkInterface(uci)
|
|
iface.Name = ifNameDHCP
|
|
iface.Proto = ifProtoDHCP
|
|
iface.IFName = ifIFNameDHCP
|
|
iface.IPAddr = ifIPAddrDHCP
|
|
iface.Netmask = ifNetmaskDHCP
|
|
iface.DNS = ifDNSDHCP
|
|
iface.IFType = ifIFTypeDHCP
|
|
iface.Metric = ifMetricDHCP
|
|
iface.DHCP.Name = ifNameDHCP
|
|
iface.DHCP.IFName = ifIFName
|
|
iface.DHCP.LeaseTime = ifLeaseTimeDHCP
|
|
iface.DHCP.RangeLimit = ifRangeLimitDHCP
|
|
iface.DHCP.StartIP = ifStartIPDHCP
|
|
|
|
cr := iface.Create()
|
|
if cr.ReturnCode != 0 {
|
|
t.Fatalf("UCIDHCPConf.Create() failed !\n\tStdout: %s\n\tStderr: %s\n\tReturnCode: %d\n\tCommand: %s\n",
|
|
cr.Stdout,
|
|
cr.Stderr,
|
|
cr.ReturnCode,
|
|
cr.Command)
|
|
}
|
|
|
|
iface.Metric = "1000"
|
|
iface.DHCP.RangeLimit = "100"
|
|
|
|
if iface.Update().ReturnCode != 0 {
|
|
t.Fatalf("UCIDHCPConf.Update() failed !")
|
|
}
|
|
}
|
|
|
|
func TestNetDeleteWithDHCP(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
iface := NewUCINetworkInterface(uci)
|
|
iface.Name = ifNameDHCP
|
|
iface.Proto = ifProtoDHCP
|
|
iface.IFName = ifIFNameDHCP
|
|
iface.IPAddr = ifIPAddrDHCP
|
|
iface.Netmask = ifNetmaskDHCP
|
|
iface.DNS = ifDNSDHCP
|
|
iface.IFType = ifIFTypeDHCP
|
|
iface.Metric = ifMetricDHCP
|
|
iface.DHCP.Name = ifNameDHCP
|
|
iface.DHCP.LeaseTime = ifLeaseTimeDHCP
|
|
iface.DHCP.RangeLimit = ifRangeLimitDHCP
|
|
iface.DHCP.StartIP = ifStartIPDHCP
|
|
|
|
if iface.Delete().ReturnCode != 0 {
|
|
t.Fatalf("UCINetworkInterface.Delete() failed !")
|
|
}
|
|
}
|