2017-10-12 21:21:36 +08:00
|
|
|
package vultr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-04-15 04:47:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/models"
|
2019-07-15 22:31:55 +08:00
|
|
|
"github.com/vultr/govultr"
|
2017-10-12 21:21:36 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConversion(t *testing.T) {
|
|
|
|
dc := &models.DomainConfig{
|
|
|
|
Name: "example.com",
|
|
|
|
}
|
|
|
|
|
2019-07-15 22:31:55 +08:00
|
|
|
records := []*govultr.DNSRecord{
|
2017-10-12 21:21:36 +08:00
|
|
|
{
|
|
|
|
Type: "A",
|
|
|
|
Name: "",
|
|
|
|
Data: "127.0.0.1",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "CNAME",
|
|
|
|
Name: "*",
|
|
|
|
Data: "example.com",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "SRV",
|
|
|
|
Name: "_ssh_.tcp",
|
|
|
|
Data: "5 22 ssh.example.com",
|
|
|
|
Priority: 5,
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "MX",
|
|
|
|
Name: "",
|
|
|
|
Data: "mail.example.com",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "NS",
|
|
|
|
Name: "",
|
|
|
|
Data: "ns1.example.net",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "TXT",
|
|
|
|
Name: "test",
|
|
|
|
Data: "\"testasd asda sdas dasd\"",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "CAA",
|
|
|
|
Name: "testasd",
|
|
|
|
Data: "0 issue \"test.example.net\"",
|
|
|
|
TTL: 300,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, record := range records {
|
2020-02-29 22:04:00 +08:00
|
|
|
rc, err := toRecordConfig(dc.Name, record)
|
2017-10-12 21:21:36 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Error("Error converting Vultr record", record)
|
|
|
|
}
|
|
|
|
|
2019-07-15 22:31:55 +08:00
|
|
|
converted := toVultrRecord(dc, rc, 0)
|
2017-10-12 21:21:36 +08:00
|
|
|
|
|
|
|
if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || converted.Priority != record.Priority || converted.TTL != record.TTL {
|
|
|
|
t.Error("Vultr record conversion mismatch", record, rc, converted)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|