diff --git a/providers/gcore/convert.go b/providers/gcore/convert.go index 835733a3a5..0bd58ee936 100644 --- a/providers/gcore/convert.go +++ b/providers/gcore/convert.go @@ -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 diff --git a/providers/gcore/convert_test.go b/providers/gcore/convert_test.go index ec0a1cd053..4a01028abb 100644 --- a/providers/gcore/convert_test.go +++ b/providers/gcore/convert_test.go @@ -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) }