feat(dns): add record accessors
This commit is contained in:
parent
a6e30edfaf
commit
d2da43f7e8
4 changed files with 68 additions and 0 deletions
|
|
@ -16,6 +16,26 @@ type NSECRecord struct {
|
|||
TTL int
|
||||
}
|
||||
|
||||
// GetName returns the owner name.
|
||||
func (r NSECRecord) GetName() string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
// GetNextDomain returns the canonical successor name.
|
||||
func (r NSECRecord) GetNextDomain() string {
|
||||
return r.NextDomain
|
||||
}
|
||||
|
||||
// GetTypeBitmap returns a copy of the NSEC type bitmap.
|
||||
func (r NSECRecord) GetTypeBitmap() []byte {
|
||||
return append([]byte(nil), r.TypeBitmap...)
|
||||
}
|
||||
|
||||
// GetTTL returns the record TTL.
|
||||
func (r NSECRecord) GetTTL() int {
|
||||
return r.TTL
|
||||
}
|
||||
|
||||
// Create constructs a reference NSEC record container.
|
||||
//
|
||||
// name := Create(".", NextName("."), TYPE_MAP_ROOT)
|
||||
|
|
|
|||
|
|
@ -33,10 +33,32 @@ func TestNSECRecordHelpers(t *testing.T) {
|
|||
t.Fatalf("Create bitmap = %x, want %x", rr.TypeBitmap, bitmap)
|
||||
}
|
||||
|
||||
if rr.GetName() != rr.Name {
|
||||
t.Fatalf("GetName() = %q, want %q", rr.GetName(), rr.Name)
|
||||
}
|
||||
|
||||
if rr.GetNextDomain() != rr.NextDomain {
|
||||
t.Fatalf("GetNextDomain() = %q, want %q", rr.GetNextDomain(), rr.NextDomain)
|
||||
}
|
||||
|
||||
if rr.GetTTL() != rr.TTL {
|
||||
t.Fatalf("GetTTL() = %d, want %d", rr.GetTTL(), rr.TTL)
|
||||
}
|
||||
|
||||
if !bytes.Equal(rr.GetTypeBitmap(), rr.TypeBitmap) {
|
||||
t.Fatalf("GetTypeBitmap() = %x, want %x", rr.GetTypeBitmap(), rr.TypeBitmap)
|
||||
}
|
||||
|
||||
bitmap[0] = 0xff
|
||||
if rr.TypeBitmap[0] != 0x01 {
|
||||
t.Fatal("Create should copy the type bitmap")
|
||||
}
|
||||
|
||||
clone := rr.GetTypeBitmap()
|
||||
clone[0] = 0xff
|
||||
if rr.TypeBitmap[0] != 0x01 {
|
||||
t.Fatal("GetTypeBitmap should return a copy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextName(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,24 @@ type Resource struct {
|
|||
Records []ResourceRecord
|
||||
}
|
||||
|
||||
// GetTTL returns the resource TTL.
|
||||
func (r *Resource) GetTTL() int {
|
||||
if r == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return r.TTL
|
||||
}
|
||||
|
||||
// GetRecords returns the resource records.
|
||||
func (r *Resource) GetRecords() []ResourceRecord {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.Records
|
||||
}
|
||||
|
||||
// ResourceJSON represents the JSON form of a DNS resource.
|
||||
type ResourceJSON struct {
|
||||
Records []json.RawMessage `json:"records"`
|
||||
|
|
|
|||
|
|
@ -248,6 +248,14 @@ func TestResourceTypeHelpers(t *testing.T) {
|
|||
if !resource.HasDS() || !resource.GetHasDS() {
|
||||
t.Fatal("HasDS should report DS records")
|
||||
}
|
||||
|
||||
if got := resource.GetTTL(); got != DEFAULT_TTL {
|
||||
t.Fatalf("GetTTL() = %d, want %d", got, DEFAULT_TTL)
|
||||
}
|
||||
|
||||
if got := resource.GetRecords(); len(got) != len(resource.Records) {
|
||||
t.Fatalf("GetRecords() = %d records, want %d", len(got), len(resource.Records))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceRecordTypeAliases(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue