github.com/teknogeek/dnscontrol@v0.2.8/providers/vultr/convert_test.go (about)

     1  package vultr
     2  
     3  import (
     4  	"testing"
     5  
     6  	vultr "github.com/JamesClonk/vultr/lib"
     7  	"github.com/StackExchange/dnscontrol/models"
     8  )
     9  
    10  func TestConversion(t *testing.T) {
    11  	dc := &models.DomainConfig{
    12  		Name: "example.com",
    13  	}
    14  
    15  	records := []*vultr.DNSRecord{
    16  		{
    17  			Type: "A",
    18  			Name: "",
    19  			Data: "127.0.0.1",
    20  			TTL:  300,
    21  		},
    22  		{
    23  			Type: "CNAME",
    24  			Name: "*",
    25  			Data: "example.com",
    26  			TTL:  300,
    27  		},
    28  		{
    29  			Type:     "SRV",
    30  			Name:     "_ssh_.tcp",
    31  			Data:     "5 22 ssh.example.com",
    32  			Priority: 5,
    33  			TTL:      300,
    34  		},
    35  		{
    36  			Type: "MX",
    37  			Name: "",
    38  			Data: "mail.example.com",
    39  			TTL:  300,
    40  		},
    41  		{
    42  			Type: "NS",
    43  			Name: "",
    44  			Data: "ns1.example.net",
    45  			TTL:  300,
    46  		},
    47  		{
    48  			Type: "TXT",
    49  			Name: "test",
    50  			Data: "\"testasd asda sdas dasd\"",
    51  			TTL:  300,
    52  		},
    53  		{
    54  			Type: "CAA",
    55  			Name: "testasd",
    56  			Data: "0 issue \"test.example.net\"",
    57  			TTL:  300,
    58  		},
    59  	}
    60  
    61  	for _, record := range records {
    62  		rc, err := toRecordConfig(dc, record)
    63  		if err != nil {
    64  			t.Error("Error converting Vultr record", record)
    65  		}
    66  
    67  		converted := toVultrRecord(dc, rc)
    68  
    69  		if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || converted.Priority != record.Priority || converted.TTL != record.TTL {
    70  			t.Error("Vultr record conversion mismatch", record, rc, converted)
    71  		}
    72  	}
    73  }