mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
e269260fbe
Updates #4923. Squashed commit of the following: commit 05322419156d18502f3f937e789df02d78971b30 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jul 9 18:18:35 2024 +0300 dhcpsvc: imp docs commit 083da3671320f7774db9c5b854e663162da9d214 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jul 9 15:28:52 2024 +0300 dhcpsvc: imp code, tests commit22e37e587e
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jul 8 19:31:43 2024 +0300 dhcpsvc: imp tests commit83ec7c54ef
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jul 8 18:56:21 2024 +0300 dhcpsvc: add db
98 lines
2.2 KiB
Go
98 lines
2.2 KiB
Go
package dhcpsvc_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/dhcpsvc"
|
|
"github.com/AdguardTeam/golibs/testutil"
|
|
)
|
|
|
|
func TestConfig_Validate(t *testing.T) {
|
|
leasesPath := filepath.Join(t.TempDir(), "leases.json")
|
|
|
|
testCases := []struct {
|
|
name string
|
|
conf *dhcpsvc.Config
|
|
wantErrMsg string
|
|
}{{
|
|
name: "nil_config",
|
|
conf: nil,
|
|
wantErrMsg: "config is nil",
|
|
}, {
|
|
name: "disabled",
|
|
conf: &dhcpsvc.Config{},
|
|
wantErrMsg: "",
|
|
}, {
|
|
name: "empty",
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
Interfaces: testInterfaceConf,
|
|
DBFilePath: leasesPath,
|
|
},
|
|
wantErrMsg: `bad domain name "": domain name is empty`,
|
|
}, {
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
LocalDomainName: testLocalTLD,
|
|
Interfaces: nil,
|
|
DBFilePath: leasesPath,
|
|
},
|
|
name: "no_interfaces",
|
|
wantErrMsg: "no interfaces specified",
|
|
}, {
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
LocalDomainName: testLocalTLD,
|
|
Interfaces: nil,
|
|
DBFilePath: leasesPath,
|
|
},
|
|
name: "no_interfaces",
|
|
wantErrMsg: "no interfaces specified",
|
|
}, {
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
LocalDomainName: testLocalTLD,
|
|
Interfaces: map[string]*dhcpsvc.InterfaceConfig{
|
|
"eth0": nil,
|
|
},
|
|
DBFilePath: leasesPath,
|
|
},
|
|
name: "nil_interface",
|
|
wantErrMsg: `interface "eth0": config is nil`,
|
|
}, {
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
LocalDomainName: testLocalTLD,
|
|
Interfaces: map[string]*dhcpsvc.InterfaceConfig{
|
|
"eth0": {
|
|
IPv4: nil,
|
|
IPv6: &dhcpsvc.IPv6Config{Enabled: false},
|
|
},
|
|
},
|
|
DBFilePath: leasesPath,
|
|
},
|
|
name: "nil_ipv4",
|
|
wantErrMsg: `interface "eth0": ipv4: config is nil`,
|
|
}, {
|
|
conf: &dhcpsvc.Config{
|
|
Enabled: true,
|
|
LocalDomainName: testLocalTLD,
|
|
Interfaces: map[string]*dhcpsvc.InterfaceConfig{
|
|
"eth0": {
|
|
IPv4: &dhcpsvc.IPv4Config{Enabled: false},
|
|
IPv6: nil,
|
|
},
|
|
},
|
|
DBFilePath: leasesPath,
|
|
},
|
|
name: "nil_ipv6",
|
|
wantErrMsg: `interface "eth0": ipv6: config is nil`,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
testutil.AssertErrorMsg(t, tc.wantErrMsg, tc.conf.Validate())
|
|
})
|
|
}
|
|
}
|