feat(action): add snake_case bind_address alias for serve
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
fcdc2c54f9
commit
1810959b89
2 changed files with 54 additions and 13 deletions
27
action.go
27
action.go
|
|
@ -25,18 +25,19 @@ var (
|
|||
)
|
||||
|
||||
const (
|
||||
actionArgBind = "bind"
|
||||
actionArgBindAddress = "bindAddress"
|
||||
actionArgIP = "ip"
|
||||
actionArgAddress = "address"
|
||||
actionArgName = "name"
|
||||
actionArgHost = "host"
|
||||
actionArgHostName = "hostname"
|
||||
actionArgPort = "port"
|
||||
actionArgDNSPort = "dnsPort"
|
||||
actionArgDNSPortSnake = "dns_port"
|
||||
actionArgHealthPort = "health_port"
|
||||
actionArgHealthPortCamel = "healthPort"
|
||||
actionArgBind = "bind"
|
||||
actionArgBindAddress = "bindAddress"
|
||||
actionArgBindAddressSnake = "bind_address"
|
||||
actionArgIP = "ip"
|
||||
actionArgAddress = "address"
|
||||
actionArgName = "name"
|
||||
actionArgHost = "host"
|
||||
actionArgHostName = "hostname"
|
||||
actionArgPort = "port"
|
||||
actionArgDNSPort = "dnsPort"
|
||||
actionArgDNSPortSnake = "dns_port"
|
||||
actionArgHealthPort = "health_port"
|
||||
actionArgHealthPortCamel = "healthPort"
|
||||
)
|
||||
|
||||
type ActionDefinition struct {
|
||||
|
|
@ -301,7 +302,7 @@ func (service *Service) handleReverseLookup(ctx context.Context, values map[stri
|
|||
|
||||
func (service *Service) handleServe(ctx context.Context, values map[string]any) (any, bool, error) {
|
||||
_ = ctx
|
||||
bind, _, err := stringActionValueOptionalFromKeys(values, actionArgBind, actionArgBindAddress)
|
||||
bind, _, err := stringActionValueOptionalFromKeys(values, actionArgBind, actionArgBindAddress, actionArgBindAddressSnake)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2925,6 +2925,46 @@ func TestServiceHandleActionServeSnakeCaseAliases(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceHandleActionServeSnakeCaseBindAddress(t *testing.T) {
|
||||
dnsPort := pickFreeTCPPort(t)
|
||||
service := NewService(ServiceOptions{
|
||||
Records: map[string]NameRecords{
|
||||
"gateway.charon.lthn": {
|
||||
A: []string{"10.10.10.10"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
payload, ok, err := service.HandleAction(ActionServe, map[string]any{
|
||||
"bind_address": "127.0.0.1",
|
||||
"dns_port": dnsPort,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("expected serve action to start with snake_case bind_address: %v", err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("expected serve action to succeed with snake_case bind_address")
|
||||
}
|
||||
|
||||
server, ok := payload.(*DNSServer)
|
||||
if !ok {
|
||||
t.Fatalf("expected DNSServer payload, got %T", payload)
|
||||
}
|
||||
if server == nil {
|
||||
t.Fatal("expected dns server from serve action")
|
||||
}
|
||||
|
||||
_, runtimeDNSPort, err := net.SplitHostPort(server.DNSAddress())
|
||||
if err != nil {
|
||||
t.Fatalf("expected dns address to include port: %v", err)
|
||||
}
|
||||
if runtimeDNSPort != strconv.Itoa(dnsPort) {
|
||||
t.Fatalf("expected dns port %d, got %q", dnsPort, runtimeDNSPort)
|
||||
}
|
||||
|
||||
_ = server.Close()
|
||||
}
|
||||
|
||||
func TestServiceResolveServePortDefaultsToStandardDNSPort(t *testing.T) {
|
||||
service := NewService(ServiceOptions{})
|
||||
if service.ResolveDNSPort() != DefaultDNSPort {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue