Skip to content

Commit

Permalink
Set default TTL when uploading zonefle
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrowadat committed Nov 12, 2023
1 parent b3604a2 commit 76a4f3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions clouddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func mergeZoneEntryIntoRrsets(dnsSpec *CloudDNSSpec, rrs []*dns.ResourceRecordSe
// Fuck's sake.
if e.TTL() != nil {
this_rrset.Ttl = int64(*e.TTL())
} else {
this_rrset.Ttl = int64(*dnsSpec.default_ttl)
}
this_rrset.Type = string(e.Type())

Expand Down
18 changes: 11 additions & 7 deletions clouddns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ func sloppyParseEntry(entry string) zonefile.Entry {

func Test_mergeZoneEntryIntoRrsets(t *testing.T) {
test_domain := "mydomain.test."
default_ttl := 300
testDnsSpec := &CloudDNSSpec{
default_ttl: &default_ttl,
domain: &test_domain,
}

type args struct {
dnsSpec *CloudDNSSpec
Expand All @@ -359,7 +364,7 @@ func Test_mergeZoneEntryIntoRrsets(t *testing.T) {
// ns and SOA records get ignored.
name: "mergeNS",
args: args{
dnsSpec: nil,
dnsSpec: testDnsSpec,
rrs: []*dns.ResourceRecordSet{},
e: sloppyParseEntry(" IN NS ns1.example.com."),
},
Expand All @@ -369,7 +374,7 @@ func Test_mergeZoneEntryIntoRrsets(t *testing.T) {
// ns and SOA records get ignored.
name: "mergeSOA",
args: args{
dnsSpec: nil,
dnsSpec: testDnsSpec,
rrs: []*dns.ResourceRecordSet{},
e: sloppyParseEntry(" IN SOA doot. root.doot. 0 0 0 0 0 0"),
},
Expand All @@ -379,16 +384,15 @@ func Test_mergeZoneEntryIntoRrsets(t *testing.T) {
// set a bare name and see if we get it qualified
name: "qualifyBareName",
args: args{
dnsSpec: &CloudDNSSpec{
domain: &test_domain,
},
rrs: []*dns.ResourceRecordSet{},
e: sloppyParseEntry("barename IN A 1.2.3.4"),
dnsSpec: testDnsSpec,
rrs: []*dns.ResourceRecordSet{},
e: sloppyParseEntry("barename IN A 1.2.3.4"),
},
want: []*dns.ResourceRecordSet{
{
Name: string("barename." + test_domain),
Type: "A",
Ttl: int64(default_ttl),
Rrdatas: []string{"1.2.3.4"},
},
},
Expand Down

0 comments on commit 76a4f3f

Please sign in to comment.