Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion providers/gcore/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
// nativeToRecord takes a DNS record from G-Core and returns a native RecordConfig struct.
func nativeToRecords(n gcoreRRSetExtended, dc *models.DomainConfig) (models.Records, error) {
var rcs models.Records
recName := dc.LabelFromFQDNWithDot(n.Name)
// G-Core returns FQDNs without a trailing dot ("www.example.com").
recName := dc.LabelFromFQDNNoDot(n.Name)
recType := n.Type

// Split G-Core's RRset into individual records
Expand Down
21 changes: 16 additions & 5 deletions providers/gcore/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@ func TestNativeToRecords(t *testing.T) {
}
tests := []struct {
name string
rrname string
rrtype string
content []any
wantLabel string
wantFQDN string
wantTarget string
}{
{"A", "A", []any{"192.0.2.1"}, "192.0.2.1"},
{"MX", "MX", []any{int64(10), "mail.example.net."}, "10 mail.example.net."},
{"CAA", "CAA", []any{int64(0), "issue", "letsencrypt.org"}, `0 issue "letsencrypt.org"`},
{"TXT", "TXT", []any{"raw text"}, `"raw text"`},
{"A", "www.example.com", "A", []any{"192.0.2.1"}, "www", "www.example.com", "192.0.2.1"},
{"apex A", "example.com", "A", []any{"192.0.2.1"}, "@", "example.com", "192.0.2.1"},
{"nested AAAA", "ygg.irc.example.com", "AAAA", []any{"2001:db8::1"}, "ygg.irc", "ygg.irc.example.com", "2001:db8::1"},
{"MX", "www.example.com", "MX", []any{int64(10), "mail.example.net."}, "www", "www.example.com", "10 mail.example.net."},
{"CAA", "example.com", "CAA", []any{int64(0), "issue", "letsencrypt.org"}, "@", "example.com", `0 issue "letsencrypt.org"`},
{"TXT", "www.example.com", "TXT", []any{"raw text"}, "www", "www.example.com", `"raw text"`},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
records, err := nativeToRecords(gcoreRRSetExtended{
Name: "www.example.com.", Type: tc.rrtype, TTL: 300,
Name: tc.rrname, Type: tc.rrtype, TTL: 300,
Records: []dnssdk.ResourceRecord{{Content: tc.content}},
}, dc)
if err != nil {
t.Fatal(err)
}
if got := records[0].GetLabel(); got != tc.wantLabel {
t.Errorf("label = %q, want %q", got, tc.wantLabel)
}
if got := records[0].GetLabelFQDN(); got != tc.wantFQDN {
t.Errorf("fqdn = %q, want %q", got, tc.wantFQDN)
}
if got := records[0].GetRDATA().String(); got != tc.wantTarget {
t.Errorf("target = %q, want %q", got, tc.wantTarget)
}
Expand Down
Loading