Standardize codebase consistency: naming, JSON tags, logging, error wrapping
- JSON tags: fix snake_case to camelCase in dnsmasq (configFile, domainsConfigured, lastRestart), crowdsec Machine (lastPush, lastHeartbeat), network (primaryIP, primaryInterface). cscli raw parsing structs keep snake_case to match CLI output. - Error wrapping: fix %v to %w in enableAuthelia for proper error chain preservation - Naming: rename dnsmasq.ConfigGenerator to dnsmasq.Manager (matches all other packages), rename ServiceStatus to Status in dnsmasq and haproxy (matches authelia, crowdsec, etc.) - Logging: standardize all slog calls to use "component" key instead of message prefixes. Affects reconcile, dnsfilter, ddns — now consistent with dnsmasq, haproxy, nftables, sse.
This commit is contained in:
@@ -18,7 +18,7 @@ func wildcardEntry(domain, ip string) DNSEntry {
|
||||
|
||||
// Test: Generate with exact-match entries produces host-record= directives
|
||||
func TestGenerate_WithEntries(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
entries := []DNSEntry{
|
||||
entry("cloud.example.com", "192.168.1.10"),
|
||||
entry("internal.example.com", "192.168.1.10"),
|
||||
@@ -39,7 +39,7 @@ func TestGenerate_WithEntries(t *testing.T) {
|
||||
|
||||
// Test: Generate with no entries still produces valid config skeleton
|
||||
func TestGenerate_NoEntries(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
|
||||
out := g.Generate(nil, []DNSEntry{})
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestGenerate_NoEntries(t *testing.T) {
|
||||
|
||||
// Test: Generate skips entries with empty IP
|
||||
func TestGenerate_EntryWithoutIP(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
|
||||
out := g.Generate(nil, []DNSEntry{entry("cloud.example.com", "")})
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestGenerate_EntryWithoutIP(t *testing.T) {
|
||||
|
||||
// Test: GenerateMainConfig produces valid base config
|
||||
func TestGenerateMainConfig(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
|
||||
out := g.GenerateMainConfig(nil)
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestGenerateMainConfig(t *testing.T) {
|
||||
|
||||
// Test: GenerateMainConfig with DHCP disabled does not include dhcp-range
|
||||
func TestGenerateMainConfig_DHCPDisabled(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = false
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestGenerateMainConfig_DHCPDisabled(t *testing.T) {
|
||||
|
||||
// Test: GenerateMainConfig with DHCP enabled includes dhcp-range
|
||||
func TestGenerateMainConfig_DHCPEnabled(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
@@ -114,7 +114,7 @@ func TestGenerateMainConfig_DHCPEnabled(t *testing.T) {
|
||||
|
||||
// Test: DHCP without gateway omits dhcp-option=3
|
||||
func TestGenerateMainConfig_DHCPNoGateway(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
@@ -129,7 +129,7 @@ func TestGenerateMainConfig_DHCPNoGateway(t *testing.T) {
|
||||
|
||||
// Test: DHCP explicit gateway is used
|
||||
func TestGenerateMainConfig_DHCPExplicitGateway(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
@@ -145,7 +145,7 @@ func TestGenerateMainConfig_DHCPExplicitGateway(t *testing.T) {
|
||||
|
||||
// Test: DHCP static leases appear in output
|
||||
func TestGenerateMainConfig_DHCPStaticLeases(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
@@ -167,7 +167,7 @@ func TestGenerateMainConfig_DHCPStaticLeases(t *testing.T) {
|
||||
|
||||
// Test: DHCP lease time defaults to 24h when not specified
|
||||
func TestGenerateMainConfig_DHCPLeaseTimeDefault(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.DHCP.Enabled = true
|
||||
cfg.Cloud.Dnsmasq.DHCP.RangeStart = "192.168.8.100"
|
||||
@@ -180,17 +180,17 @@ func TestGenerateMainConfig_DHCPLeaseTimeDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test: NewConfigGenerator uses provided path
|
||||
func TestNewConfigGenerator_CustomPath(t *testing.T) {
|
||||
g := NewConfigGenerator("/custom/path/dnsmasq.conf")
|
||||
// Test: NewManager uses provided path
|
||||
func TestNewManager_CustomPath(t *testing.T) {
|
||||
g := NewManager("/custom/path/dnsmasq.conf")
|
||||
if g.GetConfigPath() != "/custom/path/dnsmasq.conf" {
|
||||
t.Errorf("got %q, want /custom/path/dnsmasq.conf", g.GetConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
// Test: NewConfigGenerator uses default path when empty
|
||||
func TestNewConfigGenerator_DefaultPath(t *testing.T) {
|
||||
g := NewConfigGenerator("")
|
||||
// Test: NewManager uses default path when empty
|
||||
func TestNewManager_DefaultPath(t *testing.T) {
|
||||
g := NewManager("")
|
||||
if g.GetConfigPath() != "/etc/dnsmasq.d/wild-cloud.conf" {
|
||||
t.Errorf("got %q, want /etc/dnsmasq.d/wild-cloud.conf", g.GetConfigPath())
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func TestNewConfigGenerator_DefaultPath(t *testing.T) {
|
||||
|
||||
// Test: Exact-match domain produces host-record=
|
||||
func TestGenerate_ExactMatchDomain(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
out := g.Generate(globalCfg, []DNSEntry{entry("my-api.payne.io", "192.168.8.151")})
|
||||
@@ -216,7 +216,7 @@ func TestGenerate_ExactMatchDomain(t *testing.T) {
|
||||
|
||||
// Test: Wildcard domain produces address=/ without local=/
|
||||
func TestGenerate_WildcardDomain(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
out := g.Generate(globalCfg, []DNSEntry{wildcardEntry("cloud.payne.io", "192.168.8.240")})
|
||||
@@ -234,7 +234,7 @@ func TestGenerate_WildcardDomain(t *testing.T) {
|
||||
|
||||
// Test: No local=/ directives are ever generated
|
||||
func TestGenerate_NoLocalDirectives(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
entries := []DNSEntry{
|
||||
@@ -251,7 +251,7 @@ func TestGenerate_NoLocalDirectives(t *testing.T) {
|
||||
|
||||
// Test: filter-AAAA appears in generated config
|
||||
func TestGenerate_FilterAAAA(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
|
||||
out := g.Generate(nil, nil)
|
||||
|
||||
@@ -262,7 +262,7 @@ func TestGenerate_FilterAAAA(t *testing.T) {
|
||||
|
||||
// Test: Mix of exact and wildcard domains
|
||||
func TestGenerate_MixedDomains(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
entries := []DNSEntry{
|
||||
@@ -289,7 +289,7 @@ func TestGenerate_MixedDomains(t *testing.T) {
|
||||
|
||||
// Test: empty entries list produces base config with no DNS entries
|
||||
func TestGenerate_EmptyEntries(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
out := g.Generate(globalCfg, []DNSEntry{})
|
||||
@@ -310,7 +310,7 @@ func TestGenerate_EmptyEntries(t *testing.T) {
|
||||
|
||||
// Test: multiple exact-match entries each get their own DNS records
|
||||
func TestGenerate_MultipleEntries(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
globalCfg := &config.State{}
|
||||
|
||||
entries := []DNSEntry{
|
||||
@@ -329,7 +329,7 @@ func TestGenerate_MultipleEntries(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerate_ConfFile(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
g.SetFilterConfPath("/var/lib/wild-central/dns-filter/hosts.blocked")
|
||||
|
||||
out := g.Generate(nil, nil)
|
||||
@@ -343,7 +343,7 @@ func TestGenerate_ConfFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerate_NoConfFileWhenEmpty(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
// addnHostsPath is empty by default
|
||||
|
||||
out := g.Generate(nil, nil)
|
||||
@@ -354,7 +354,7 @@ func TestGenerate_NoConfFileWhenEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerateMainConfig_ConfFile(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
g.SetFilterConfPath("/tmp/hosts.blocked")
|
||||
|
||||
cfg := &config.State{}
|
||||
@@ -367,7 +367,7 @@ func TestGenerateMainConfig_ConfFile(t *testing.T) {
|
||||
|
||||
// Test: nil config doesn't panic, uses auto-detect for IP
|
||||
func TestGenerate_NilConfig(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
|
||||
out := g.Generate(nil, []DNSEntry{})
|
||||
|
||||
@@ -381,7 +381,7 @@ func TestGenerate_NilConfig(t *testing.T) {
|
||||
|
||||
// Test: when cfg.Cloud.Dnsmasq.IP is set, uses that instead of auto-detect
|
||||
func TestGenerate_ConfiguredDnsmasqIP(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
cfg.Cloud.Dnsmasq.IP = "192.168.8.100"
|
||||
|
||||
@@ -394,7 +394,7 @@ func TestGenerate_ConfiguredDnsmasqIP(t *testing.T) {
|
||||
|
||||
// Test: verify no leaked empty entries appear
|
||||
func TestGenerate_NoLeakedEmptyEntries(t *testing.T) {
|
||||
g := NewConfigGenerator("/tmp/test-dnsmasq.conf")
|
||||
g := NewManager("/tmp/test-dnsmasq.conf")
|
||||
cfg := &config.State{}
|
||||
|
||||
cases := []struct {
|
||||
|
||||
Reference in New Issue
Block a user