feat(dns): add GetType aliases for resource records
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
994234f65f
commit
4e0e5e7be9
2 changed files with 72 additions and 0 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue