feat(dns): default serve action port when unset
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
f27ec3438a
commit
01df7589bd
3 changed files with 26 additions and 3 deletions
|
|
@ -289,7 +289,7 @@ func (service *Service) handleServe(ctx context.Context, values map[string]any)
|
|||
return nil, false, err
|
||||
}
|
||||
if !portProvided {
|
||||
port = service.dnsPort
|
||||
port = service.resolveServePort()
|
||||
}
|
||||
result, err := service.Serve(bind, port)
|
||||
if err != nil {
|
||||
|
|
@ -298,6 +298,13 @@ func (service *Service) handleServe(ctx context.Context, values map[string]any)
|
|||
return result, true, nil
|
||||
}
|
||||
|
||||
func (service *Service) resolveServePort() int {
|
||||
if service == nil || service.dnsPort <= 0 {
|
||||
return DefaultDNSPort
|
||||
}
|
||||
return service.dnsPort
|
||||
}
|
||||
|
||||
func stringActionValue(values map[string]any, key string) (string, error) {
|
||||
if values == nil {
|
||||
return "", errActionMissingValue
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
// service := dns.NewService(dns.ServiceOptions{})
|
||||
// fmt.Println(dns.DefaultTreeRootCheckInterval)
|
||||
const DefaultTreeRootCheckInterval = 15 * time.Second
|
||||
const DefaultDNSPort = 53
|
||||
|
||||
// NameRecords stores the cached DNS records for one name.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -2233,6 +2233,21 @@ func TestServiceHandleActionServeDefaultsPortFromServiceConfiguration(t *testing
|
|||
_ = dnsServer.Close()
|
||||
}
|
||||
|
||||
func TestServiceResolveServePortDefaultsToStandardDNSPort(t *testing.T) {
|
||||
service := NewService(ServiceOptions{})
|
||||
if service.resolveServePort() != DefaultDNSPort {
|
||||
t.Fatalf("expected serve to default to standard DNS port %d, got %d", DefaultDNSPort, service.resolveServePort())
|
||||
}
|
||||
|
||||
customPort := 1053
|
||||
customService := NewService(ServiceOptions{
|
||||
DNSPort: customPort,
|
||||
})
|
||||
if customService.resolveServePort() != customPort {
|
||||
t.Fatalf("expected resolveServePort to honor configured DNSPort, got %d", customService.resolveServePort())
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceActionNamesExposeAllRFCActions(t *testing.T) {
|
||||
service := NewService(ServiceOptions{})
|
||||
|
||||
|
|
@ -2636,8 +2651,8 @@ func TestServiceDiscoverAliasesFallsBackToMainchainAliasRPCUsingHSDURL(t *testin
|
|||
defer server.Close()
|
||||
|
||||
service := NewService(ServiceOptions{
|
||||
HSDURL: server.URL,
|
||||
Records: map[string]NameRecords{},
|
||||
HSDURL: server.URL,
|
||||
Records: map[string]NameRecords{},
|
||||
})
|
||||
|
||||
if err := service.DiscoverAliases(context.Background()); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue