It's state, not config.
This commit is contained in:
@@ -209,7 +209,7 @@ func TestGenerateMainConfig_DHCPEnabled(t *testing.T) {
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeEnd = "192.168.8.200"
|
||||
cfg.Cloud.Dnsmasq.DHCP.LeaseTime = "12h"
|
||||
cfg.Cloud.Router.IP = "192.168.8.1"
|
||||
cfg.Cloud.Dnsmasq.DHCP.Gateway = "192.168.8.1"
|
||||
|
||||
out := g.GenerateMainConfig(cfg)
|
||||
|
||||
@@ -221,24 +221,23 @@ func TestGenerateMainConfig_DHCPEnabled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test: DHCP gateway falls back to router IP when not set
|
||||
func TestGenerateMainConfig_DHCPGatewayFallback(t *testing.T) {
|
||||
// Test: DHCP without gateway omits dhcp-option=3
|
||||
func TestGenerateMainConfig_DHCPNoGateway(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.GlobalConfig{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeEnd = "192.168.8.200"
|
||||
cfg.Cloud.Router.IP = "192.168.8.1"
|
||||
// Gateway not set — should fall back to router IP
|
||||
// No gateway set
|
||||
|
||||
out := g.GenerateMainConfig(cfg)
|
||||
|
||||
if !strings.Contains(out, "dhcp-option=3,192.168.8.1") {
|
||||
t.Errorf("expected router IP as fallback gateway, got:\n%s", out)
|
||||
if strings.Contains(out, "dhcp-option=3,") {
|
||||
t.Errorf("expected no gateway dhcp-option when gateway not set, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// Test: DHCP explicit gateway takes precedence over router IP
|
||||
// Test: DHCP explicit gateway is used
|
||||
func TestGenerateMainConfig_DHCPExplicitGateway(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.GlobalConfig{}
|
||||
@@ -246,16 +245,12 @@ func TestGenerateMainConfig_DHCPExplicitGateway(t *testing.T) {
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeEnd = "192.168.8.200"
|
||||
cfg.Cloud.Dnsmasq.DHCP.Gateway = "192.168.8.254"
|
||||
cfg.Cloud.Router.IP = "192.168.8.1"
|
||||
|
||||
out := g.GenerateMainConfig(cfg)
|
||||
|
||||
if !strings.Contains(out, "dhcp-option=3,192.168.8.254") {
|
||||
t.Errorf("expected explicit gateway in dhcp-option=3, got:\n%s", out)
|
||||
}
|
||||
if strings.Contains(out, "dhcp-option=3,192.168.8.1") {
|
||||
t.Errorf("router IP should not appear as gateway when explicit gateway set, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// Test: DHCP static leases appear in output
|
||||
|
||||
Reference in New Issue
Block a user