owrt/uci_dhcp_conf_test.go

103 lines
2.5 KiB
Go
Raw Normal View History

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"
2018-10-26 11:39:47 +02:00
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
2018-10-26 11:39:47 +02:00
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
2018-10-26 11:39:47 +02:00
iface.DHCP.IFName = ifIFName
iface.DHCP.LeaseTime = ifLeaseTimeDHCP
iface.DHCP.RangeLimit = ifRangeLimitDHCP
iface.DHCP.StartIP = ifStartIPDHCP
2018-10-26 11:39:47 +02:00
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 {
2018-10-26 11:39:47 +02:00
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
2018-10-26 11:39:47 +02:00
iface.DHCP.LeaseTime = ifLeaseTimeDHCP
iface.DHCP.RangeLimit = ifRangeLimitDHCP
iface.DHCP.StartIP = ifStartIPDHCP
if iface.Delete().ReturnCode != 0 {
t.Fatalf("UCINetworkInterface.Delete() failed !")
}
}