github.com/philhug/dnscontrol@v0.2.4-0.20180625181521-921fa9849001/providers/namedotcom/records_test.go (about)

     1  package namedotcom
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  var txtData = []struct {
     9  	decoded []string
    10  	encoded string
    11  }{
    12  	{[]string{`simple`}, `simple`},
    13  	{[]string{`changed`}, `changed`},
    14  	{[]string{`with spaces`}, `with spaces`},
    15  	{[]string{`with whitespace`}, `with whitespace`},
    16  	{[]string{"one", "two"}, `"one""two"`},
    17  	{[]string{"eh", "bee", "cee"}, `"eh""bee""cee"`},
    18  	{[]string{"o\"ne", "tw\"o"}, `"o\"ne""tw\"o"`},
    19  	{[]string{"dimple"}, `dimple`},
    20  	{[]string{"fun", "two"}, `"fun""two"`},
    21  	{[]string{"eh", "bzz", "cee"}, `"eh""bzz""cee"`},
    22  }
    23  
    24  func TestEncodeTxt(t *testing.T) {
    25  	// Test encoded the lists of strings into a string:
    26  	for i, test := range txtData {
    27  		enc := encodeTxt(test.decoded)
    28  		if enc != test.encoded {
    29  			t.Errorf("%v: txt\n    data: []string{%v}\nexpected: %s\n     got: %s",
    30  				i, "`"+strings.Join(test.decoded, "`, `")+"`", test.encoded, enc)
    31  		}
    32  	}
    33  }
    34  
    35  func TestDecodeTxt(t *testing.T) {
    36  	// Test decoded a string into the list of strings:
    37  	for i, test := range txtData {
    38  		data := test.encoded
    39  		got := decodeTxt(data)
    40  		wanted := test.decoded
    41  		if len(got) != len(wanted) {
    42  			t.Errorf("%v: txt\n  decode: %v\nexpected: `%v`\n     got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
    43  		} else {
    44  			for j := range got {
    45  				if got[j] != wanted[j] {
    46  					t.Errorf("%v: txt\n  decode: %v\nexpected: `%v`\n     got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
    47  				}
    48  			}
    49  		}
    50  	}
    51  }