Add explicit DNS configuration aliases
This commit is contained in:
parent
5968a4cc50
commit
25d4b85e56
2 changed files with 43 additions and 0 deletions
25
service.go
25
service.go
|
|
@ -178,11 +178,25 @@ type ServiceOptions struct {
|
|||
// })
|
||||
type ServiceConfiguration = ServiceOptions
|
||||
|
||||
// DNSServiceConfiguration is the explicit DNS-prefixed configuration alias.
|
||||
//
|
||||
// service := dns.NewDNSServiceFromConfiguration(dns.DNSServiceConfiguration{
|
||||
// Records: map[string]dns.NameRecords{
|
||||
// "gateway.charon.lthn": {A: []string{"10.10.10.10"}},
|
||||
// },
|
||||
// })
|
||||
type DNSServiceConfiguration = ServiceOptions
|
||||
|
||||
// ServiceConfig is kept for compatibility with older call sites.
|
||||
//
|
||||
// Deprecated: use ServiceConfiguration instead.
|
||||
type ServiceConfig = ServiceOptions
|
||||
|
||||
// DNSServiceConfig is kept for compatibility with older call sites.
|
||||
//
|
||||
// Deprecated: use DNSServiceConfiguration instead.
|
||||
type DNSServiceConfig = ServiceOptions
|
||||
|
||||
// DNSServiceOptions is the preferred long-form type name for service configuration.
|
||||
//
|
||||
// service := dns.NewDNSServiceFromOptions(dns.DNSServiceOptions{
|
||||
|
|
@ -317,6 +331,17 @@ func NewDNSServiceFromOptions(options DNSServiceOptions) *Service {
|
|||
return NewDNSService(options)
|
||||
}
|
||||
|
||||
// NewDNSServiceFromConfiguration is the explicit constructor name for the DNS configuration alias.
|
||||
//
|
||||
// service := dns.NewDNSServiceFromConfiguration(dns.DNSServiceConfiguration{
|
||||
// Records: map[string]dns.NameRecords{
|
||||
// "gateway.charon.lthn": {A: []string{"10.10.10.10"}},
|
||||
// },
|
||||
// })
|
||||
func NewDNSServiceFromConfiguration(options DNSServiceConfiguration) *Service {
|
||||
return NewDNSService(options)
|
||||
}
|
||||
|
||||
// NewDNSServiceWithContextRegistrar is an explicit constructor name for action wiring.
|
||||
//
|
||||
// service := dns.NewDNSServiceWithContextRegistrar(dns.DNSServiceOptions{}, actionRegistrar)
|
||||
|
|
|
|||
|
|
@ -175,6 +175,24 @@ func TestNewDNSServiceAliasToExistingConstructor(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewDNSServiceFromConfigurationAliasBuildsService(t *testing.T) {
|
||||
service := NewDNSServiceFromConfiguration(DNSServiceConfiguration{
|
||||
Records: map[string]NameRecords{
|
||||
"gateway.charon.lthn": {
|
||||
A: []string{"10.10.10.10"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
result, ok := service.ResolveAddress("gateway.charon.lthn")
|
||||
if !ok {
|
||||
t.Fatal("expected service constructed from NewDNSServiceFromConfiguration alias to resolve")
|
||||
}
|
||||
if len(result.Addresses) != 1 || result.Addresses[0] != "10.10.10.10" {
|
||||
t.Fatalf("unexpected resolve result from NewDNSServiceFromConfiguration: %#v", result.Addresses)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDNSServiceWithRegistrarAliasRegistersActions(t *testing.T) {
|
||||
recorder := &actionRecorder{}
|
||||
service := NewDNSServiceWithRegistrar(ServiceOptions{}, recorder)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue