feat(lns): add service utility wrappers
This commit is contained in:
parent
ffcaa51187
commit
41eeee936c
2 changed files with 144 additions and 0 deletions
60
lns.go
60
lns.go
|
|
@ -332,6 +332,66 @@ func GetPrevName(tld string) string {
|
|||
return PrevName(tld)
|
||||
}
|
||||
|
||||
// NewClaim constructs an empty claim wrapper.
|
||||
func (s *Service) NewClaim() *Claim {
|
||||
return primitives.NewClaim()
|
||||
}
|
||||
|
||||
// GetNewClaim is an alias for NewClaim.
|
||||
func (s *Service) GetNewClaim() *Claim {
|
||||
return s.NewClaim()
|
||||
}
|
||||
|
||||
// Create constructs a reference NSEC record container.
|
||||
func (s *Service) Create(name, nextDomain string, typeBitmap []byte) NSECRecord {
|
||||
return dnspkg.Create(name, nextDomain, typeBitmap)
|
||||
}
|
||||
|
||||
// GetCreate is an alias for Create.
|
||||
func (s *Service) GetCreate(name, nextDomain string, typeBitmap []byte) NSECRecord {
|
||||
return s.Create(name, nextDomain, typeBitmap)
|
||||
}
|
||||
|
||||
// NextName returns the canonical successor for a top-level domain name.
|
||||
func (s *Service) NextName(tld string) string {
|
||||
return dnspkg.NextName(tld)
|
||||
}
|
||||
|
||||
// GetNextName is an alias for NextName.
|
||||
func (s *Service) GetNextName(tld string) string {
|
||||
return s.NextName(tld)
|
||||
}
|
||||
|
||||
// PrevName returns the canonical predecessor for a top-level domain name.
|
||||
func (s *Service) PrevName(tld string) string {
|
||||
return dnspkg.PrevName(tld)
|
||||
}
|
||||
|
||||
// GetPrevName is an alias for PrevName.
|
||||
func (s *Service) GetPrevName(tld string) string {
|
||||
return s.PrevName(tld)
|
||||
}
|
||||
|
||||
// NewResource constructs a DNS resource with the reference default TTL.
|
||||
func (s *Service) NewResource() *Resource {
|
||||
return dnspkg.NewResource()
|
||||
}
|
||||
|
||||
// GetNewResource is an alias for NewResource.
|
||||
func (s *Service) GetNewResource() *Resource {
|
||||
return s.NewResource()
|
||||
}
|
||||
|
||||
// DecodeResource decodes a raw DNS resource payload.
|
||||
func (s *Service) DecodeResource(raw []byte) (*Resource, error) {
|
||||
return dnspkg.DecodeResource(raw)
|
||||
}
|
||||
|
||||
// GetDecodeResource is an alias for DecodeResource.
|
||||
func (s *Service) GetDecodeResource(raw []byte) (*Resource, error) {
|
||||
return s.DecodeResource(raw)
|
||||
}
|
||||
|
||||
// OnStartup satisfies core.Startable so LNS participates in Core lifecycle
|
||||
// discovery without requiring any explicit setup.
|
||||
func (s *Service) OnStartup(context.Context) core.Result {
|
||||
|
|
|
|||
84
lns_test.go
84
lns_test.go
|
|
@ -3,6 +3,7 @@
|
|||
package lns
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha3"
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
|
|
@ -863,6 +864,89 @@ func TestServiceGetBlindAndGetTypeNameAliases(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceUtilityAliases(t *testing.T) {
|
||||
svc := &Service{}
|
||||
|
||||
if svc.NewClaim() == nil {
|
||||
t.Fatal("NewClaim should return a claim wrapper")
|
||||
}
|
||||
|
||||
if svc.GetNewClaim() == nil {
|
||||
t.Fatal("GetNewClaim should alias NewClaim")
|
||||
}
|
||||
|
||||
if got := svc.NextName("ExAmPle."); got != "example\x00." {
|
||||
t.Fatalf("NextName returned %q", got)
|
||||
}
|
||||
|
||||
if got := svc.GetNextName("ExAmPle."); got != "example\x00." {
|
||||
t.Fatalf("GetNextName returned %q", got)
|
||||
}
|
||||
|
||||
if got := svc.PrevName("ExAmPle."); got != "exampld\xff." {
|
||||
t.Fatalf("PrevName returned %q", got)
|
||||
}
|
||||
|
||||
if got := svc.GetPrevName("ExAmPle."); got != "exampld\xff." {
|
||||
t.Fatalf("GetPrevName returned %q", got)
|
||||
}
|
||||
|
||||
record := svc.Create(".", svc.NextName("."), TYPE_MAP_ROOT)
|
||||
if record.Name != "." {
|
||||
t.Fatalf("Create Name = %q, want %q", record.Name, ".")
|
||||
}
|
||||
|
||||
if record.NextDomain != "\x00." {
|
||||
t.Fatalf("Create NextDomain = %q, want %q", record.NextDomain, "\x00.")
|
||||
}
|
||||
|
||||
if record.TTL != DEFAULT_TTL {
|
||||
t.Fatalf("Create TTL = %d, want %d", record.TTL, DEFAULT_TTL)
|
||||
}
|
||||
|
||||
if !bytes.Equal(record.TypeBitmap, TYPE_MAP_ROOT) {
|
||||
t.Fatalf("Create TypeBitmap = %x, want %x", record.TypeBitmap, TYPE_MAP_ROOT)
|
||||
}
|
||||
|
||||
if svc.GetCreate("foo", "bar", TYPE_MAP_NS).TTL != DEFAULT_TTL {
|
||||
t.Fatal("GetCreate should alias Create")
|
||||
}
|
||||
|
||||
resource := svc.NewResource()
|
||||
if resource == nil {
|
||||
t.Fatal("NewResource should return a resource")
|
||||
}
|
||||
|
||||
if resource.TTL != DEFAULT_TTL {
|
||||
t.Fatalf("NewResource TTL = %d, want %d", resource.TTL, DEFAULT_TTL)
|
||||
}
|
||||
|
||||
if svc.GetNewResource() == nil {
|
||||
t.Fatal("GetNewResource should return a resource")
|
||||
}
|
||||
|
||||
resource.Records = []ResourceRecord{TXTRecord{Entries: []string{"hello"}}}
|
||||
encoded, err := resource.Encode()
|
||||
if err != nil {
|
||||
t.Fatalf("Resource.Encode returned error: %v", err)
|
||||
}
|
||||
|
||||
decoded, err := svc.DecodeResource(encoded)
|
||||
if err != nil {
|
||||
t.Fatalf("DecodeResource returned error: %v", err)
|
||||
}
|
||||
|
||||
if len(decoded.Records) != len(resource.Records) {
|
||||
t.Fatalf("DecodeResource records = %d, want %d", len(decoded.Records), len(resource.Records))
|
||||
}
|
||||
|
||||
if got, err := svc.GetDecodeResource(encoded); err != nil {
|
||||
t.Fatalf("GetDecodeResource returned error: %v", err)
|
||||
} else if got.TTL != decoded.TTL || len(got.Records) != len(decoded.Records) {
|
||||
t.Fatal("GetDecodeResource should alias DecodeResource")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceCoreAccessors(t *testing.T) {
|
||||
runtime := core.NewServiceRuntime(nil, serviceOptions{})
|
||||
svc := &Service{ServiceRuntime: runtime}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue