Add explicit DNS runtime alias

This commit is contained in:
Virgil 2026-04-04 03:36:44 +00:00
parent d964b98e0c
commit 6b9a6c1bba
2 changed files with 18 additions and 10 deletions

View file

@ -45,6 +45,13 @@ type ServiceRuntime struct {
HTTPServer *HealthServer HTTPServer *HealthServer
} }
// DNSServiceRuntime is the explicit long-form alias for ServiceRuntime.
//
// runtime, err := service.ServeAll("127.0.0.1", 53, 5554)
// var dnsRuntime dns.DNSServiceRuntime = *runtime
// fmt.Println(dnsRuntime.DNSAddress(), dnsRuntime.HealthAddress())
type DNSServiceRuntime = ServiceRuntime
// Address is the compatibility alias for HealthAddress. // Address is the compatibility alias for HealthAddress.
// //
// runtime, err := service.ServeAll("127.0.0.1", 53, 5554) // runtime, err := service.ServeAll("127.0.0.1", 53, 5554)

View file

@ -821,24 +821,25 @@ func TestServiceServeAllStartsDNSAndHTTPTogether(t *testing.T) {
defer func() { defer func() {
_ = runtime.Close() _ = runtime.Close()
}() }()
var dnsRuntime DNSServiceRuntime = *runtime
if runtime.DNSAddress() == "" { if dnsRuntime.DNSAddress() == "" {
t.Fatal("expected DNS address from combined runtime") t.Fatal("expected DNS address from combined runtime")
} }
if runtime.HealthAddress() == "" { if dnsRuntime.HealthAddress() == "" {
t.Fatal("expected health address from combined runtime") t.Fatal("expected health address from combined runtime")
} }
if runtime.Address() != runtime.HealthAddress() { if dnsRuntime.Address() != dnsRuntime.HealthAddress() {
t.Fatalf("expected runtime Address alias to match HealthAddress, got %q and %q", runtime.Address(), runtime.HealthAddress()) t.Fatalf("expected runtime Address alias to match HealthAddress, got %q and %q", dnsRuntime.Address(), dnsRuntime.HealthAddress())
} }
if runtime.DNS.Address() != runtime.DNSAddress() { if dnsRuntime.DNS.Address() != dnsRuntime.DNSAddress() {
t.Fatalf("expected DNSAddress and Address to match, got %q and %q", runtime.DNS.DNSAddress(), runtime.DNS.Address()) t.Fatalf("expected DNSAddress and Address to match, got %q and %q", dnsRuntime.DNS.DNSAddress(), dnsRuntime.DNS.Address())
} }
if runtime.HTTPAddress() != runtime.HealthAddress() { if dnsRuntime.HTTPAddress() != dnsRuntime.HealthAddress() {
t.Fatalf("expected HTTPAddress and HealthAddress to match, got %q and %q", runtime.HTTPAddress(), runtime.HealthAddress()) t.Fatalf("expected HTTPAddress and HealthAddress to match, got %q and %q", dnsRuntime.HTTPAddress(), dnsRuntime.HealthAddress())
} }
response, err := http.Get("http://" + runtime.HealthAddress() + "/health") response, err := http.Get("http://" + dnsRuntime.HealthAddress() + "/health")
if err != nil { if err != nil {
t.Fatalf("expected combined HTTP health endpoint to respond: %v", err) t.Fatalf("expected combined HTTP health endpoint to respond: %v", err)
} }
@ -853,7 +854,7 @@ func TestServiceServeAllStartsDNSAndHTTPTogether(t *testing.T) {
client := dnsprotocol.Client{} client := dnsprotocol.Client{}
request := new(dnsprotocol.Msg) request := new(dnsprotocol.Msg)
request.SetQuestion("gateway.charon.lthn.", dnsprotocol.TypeA) request.SetQuestion("gateway.charon.lthn.", dnsprotocol.TypeA)
dnsResponse := exchangeWithRetry(t, client, request, runtime.DNSAddress()) dnsResponse := exchangeWithRetry(t, client, request, dnsRuntime.DNSAddress())
if dnsResponse.Rcode != dnsprotocol.RcodeSuccess { if dnsResponse.Rcode != dnsprotocol.RcodeSuccess {
t.Fatalf("unexpected combined DNS rcode: %d", dnsResponse.Rcode) t.Fatalf("unexpected combined DNS rcode: %d", dnsResponse.Rcode)
} }