Skip to content

Commit 308e7b5

Browse files
committed
Update tests
1 parent 0b43b31 commit 308e7b5

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

integrationTest/helpers_integration_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,14 @@ func dname(name, target string) *models.RecordConfig {
404404
}
405405

406406
func ds(name string, keyTag uint16, algorithm, digestType uint8, digest string) *models.RecordConfig {
407-
r := makeRec(name, "", "DS")
408-
panicOnErr(r.SetTargetDS(keyTag, algorithm, digestType, digest))
409-
return r
407+
rec, err := rtypecontrol.NewRecordConfigFromRaw(rtypecontrol.FromRawOpts{
408+
Type: "DS",
409+
TTL: 300,
410+
Args: []any{name, keyTag, algorithm, digestType, digest},
411+
DCN: globalDCN,
412+
})
413+
panicOnErr(err)
414+
return rec
410415
}
411416

412417
func dnskey(name string, flags uint16, protocol, algorithm uint8, publicKey string) *models.RecordConfig {

pkg/rtype/ds.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package rtype
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/StackExchange/dnscontrol/v4/models"
7+
"github.com/StackExchange/dnscontrol/v4/pkg/domaintags"
8+
"github.com/StackExchange/dnscontrol/v4/pkg/rtypecontrol"
9+
"github.com/miekg/dns"
10+
)
11+
12+
func init() {
13+
rtypecontrol.Register(&DS{})
14+
}
15+
16+
// DS RR.
17+
type DS struct {
18+
dns.DS
19+
}
20+
21+
// Name returns the DNS record type as a string.
22+
func (handle *DS) Name() string {
23+
return "DS"
24+
}
25+
26+
// FromArgs fills in the RecordConfig from []any, which is typically from a parsed config file.
27+
func (handle *DS) FromArgs(dcn *domaintags.DomainNameVarieties, rec *models.RecordConfig, args []any) error {
28+
if err := rtypecontrol.PaveArgs(args[1:], "wbbs"); err != nil {
29+
return fmt.Errorf("ERROR: (%s) [DS(%q, %v)]: %w",
30+
rec.FilePos,
31+
rec.Name, rtypecontrol.StringifyQuoted(args[1:]),
32+
err)
33+
}
34+
fields := &DS{
35+
dns.DS{
36+
KeyTag: args[1].(uint16),
37+
Algorithm: args[2].(uint8),
38+
DigestType: args[3].(uint8),
39+
Digest: args[4].(string),
40+
},
41+
}
42+
43+
return handle.FromStruct(dcn, rec, args[0].(string), fields)
44+
}
45+
46+
// FromStruct fills in the RecordConfig from a struct, typically from an API response.
47+
func (handle *DS) FromStruct(dcn *domaintags.DomainNameVarieties, rec *models.RecordConfig, name string, fields any) error {
48+
rec.F = fields
49+
50+
rec.ZonefilePartial = rec.GetTargetRFC1035Quoted()
51+
rec.Comparable = rec.ZonefilePartial
52+
53+
handle.CopyToLegacyFields(rec)
54+
return nil
55+
}
56+
57+
// CopyToLegacyFields populates the legacy fields of the RecordConfig using the fields in .F.
58+
func (handle *DS) CopyToLegacyFields(rec *models.RecordConfig) {
59+
ds := rec.F.(*DS)
60+
_ = rec.SetTargetDS(ds.KeyTag, ds.Algorithm, ds.DigestType, ds.Digest)
61+
}

0 commit comments

Comments
 (0)