From 33a98aa9372de138f51bc8f3e925be5e20c0f04e Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 20 Mar 2020 11:45:22 +0300 Subject: [PATCH] minor --- home/openwrt.go | 2 +- home/openwrt_test.go | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/home/openwrt.go b/home/openwrt.go index 528a620f..5761542e 100644 --- a/home/openwrt.go +++ b/home/openwrt.go @@ -200,7 +200,7 @@ func (oc *openwrtConfig) readResolvConf(data []byte) { } } -// Convert system config parameters to the format suitable by our yaml config +// Convert system config parameters to our yaml config format func (oc *openwrtConfig) prepareOutput() error { oc.iface = "br-lan" diff --git a/home/openwrt_test.go b/home/openwrt_test.go index dacba768..1c9d95ce 100644 --- a/home/openwrt_test.go +++ b/home/openwrt_test.go @@ -47,6 +47,32 @@ nameserver 1.2.3.4`) assert.Equal(t, "abab::1234", oc.bsDNS[0]) assert.Equal(t, "1.2.3.4", oc.bsDNS[1]) + tmp := oc.ipaddr + oc.dhcpStart = "invalid" // not an IP + assert.True(t, oc.prepareOutput() != nil) + oc.ipaddr = tmp + + tmp = oc.dhcpStart + oc.dhcpStart = "invalid" // not an integer + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpStart = "256" //byte overflow + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpStart = tmp + + tmp = oc.dhcpLimit + oc.dhcpLimit = "invalid" // not an integer + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpLimit = "200" //byte overflow + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpLimit = tmp + + tmp = oc.dhcpLeasetime + oc.dhcpLeasetime = "12m" // not an 'h' + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpLeasetime = "invalid" // not an integer + assert.True(t, oc.prepareOutput() != nil) + oc.dhcpLeasetime = tmp + data = []byte(`config host '123412341234' option mac '12:34:12:34:12:34' option ip '192.168.8.2' @@ -56,5 +82,4 @@ option name 'hostname'`) assert.Equal(t, "12:34:12:34:12:34", oc.leases[0].HWAddr.String()) assert.Equal(t, "192.168.8.2", oc.leases[0].IP.String()) assert.Equal(t, "hostname", oc.leases[0].Hostname) - }