From 4e0e5e7be90a458dfaa52ab0f9a3a3b520ddcac1 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 07:44:14 +0000 Subject: [PATCH] feat(dns): add GetType aliases for resource records Co-Authored-By: Virgil --- pkg/dns/resource.go | 21 +++++++++++++++++ pkg/dns/resource_test.go | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/pkg/dns/resource.go b/pkg/dns/resource.go index 3542b83..02db328 100644 --- a/pkg/dns/resource.go +++ b/pkg/dns/resource.go @@ -149,24 +149,45 @@ func GetNewResource() *Resource { // Type returns the DNS record type. func (DSRecord) Type() HSType { return HSTypeDS } +// GetType is an alias for Type. +func (r DSRecord) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (NSRecord) Type() HSType { return HSTypeNS } +// GetType is an alias for Type. +func (r NSRecord) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (GLUE4Record) Type() HSType { return HSTypeGLUE4 } +// GetType is an alias for Type. +func (r GLUE4Record) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (GLUE6Record) Type() HSType { return HSTypeGLUE6 } +// GetType is an alias for Type. +func (r GLUE6Record) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (SYNTH4Record) Type() HSType { return HSTypeSYNTH4 } +// GetType is an alias for Type. +func (r SYNTH4Record) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (SYNTH6Record) Type() HSType { return HSTypeSYNTH6 } +// GetType is an alias for Type. +func (r SYNTH6Record) GetType() HSType { return r.Type() } + // Type returns the DNS record type. func (TXTRecord) Type() HSType { return HSTypeTXT } +// GetType is an alias for Type. +func (r TXTRecord) GetType() HSType { return r.Type() } + // NS returns the synthesized target host for a SYNTH4 record. func (r SYNTH4Record) NS() string { if !r.Address.Is4() { diff --git a/pkg/dns/resource_test.go b/pkg/dns/resource_test.go index cf9ddb3..56d14a1 100644 --- a/pkg/dns/resource_test.go +++ b/pkg/dns/resource_test.go @@ -242,6 +242,57 @@ func TestResourceTypeHelpers(t *testing.T) { } } +func TestResourceRecordTypeAliases(t *testing.T) { + cases := []struct { + name string + value ResourceRecord + want HSType + }{ + {name: "ds", value: DSRecord{}, want: HSTypeDS}, + {name: "ns", value: NSRecord{}, want: HSTypeNS}, + {name: "glue4", value: GLUE4Record{}, want: HSTypeGLUE4}, + {name: "glue6", value: GLUE6Record{}, want: HSTypeGLUE6}, + {name: "synth4", value: SYNTH4Record{}, want: HSTypeSYNTH4}, + {name: "synth6", value: SYNTH6Record{}, want: HSTypeSYNTH6}, + {name: "txt", value: TXTRecord{}, want: HSTypeTXT}, + } + + for _, tc := range cases { + switch rr := tc.value.(type) { + case DSRecord: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case NSRecord: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case GLUE4Record: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case GLUE6Record: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case SYNTH4Record: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case SYNTH6Record: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + case TXTRecord: + if got := rr.GetType(); got != tc.want { + t.Fatalf("%s GetType() = %d, want %d", tc.name, got, tc.want) + } + default: + t.Fatalf("%s: unexpected record type %T", tc.name, tc.value) + } + } +} + func TestResourceToNSEC(t *testing.T) { cases := []struct { name string