Skip to content

Commit

Permalink
Make the tests more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewci0 committed Jul 14, 2023
1 parent 8cd7c95 commit e76c681
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions registry/txt_test.go
Expand Up @@ -18,6 +18,7 @@ package registry

import (
"context"
"fmt"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -1172,6 +1173,7 @@ func TestExtractRecordTypeDefaultPosition(t *testing.T) {
expectedType: "",
},
}

for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
actualName, actualType := extractRecordTypeDefaultPosition(tc.input)
Expand All @@ -1182,105 +1184,120 @@ func TestExtractRecordTypeDefaultPosition(t *testing.T) {
}

func TestToEndpointNameNewTXT(t *testing.T) {
type testCase struct {
tests := []struct {
name string
mapper affixNameMapper
domain string
txtDomain string
recordType string
}

testCases := []testCase{
}{
{
name: "prefix",
mapper: newaffixNameMapper("foo", "", ""),
domain: "example.com",
recordType: "A",
txtDomain: "fooa-example.com",
},
{
name: "suffix",
mapper: newaffixNameMapper("", "foo", ""),
domain: "example.com",
recordType: "AAAA",
txtDomain: "aaaa-examplefoo.com",
},
{
name: "prefix with dash",
mapper: newaffixNameMapper("foo-", "", ""),
domain: "example.com",
recordType: "A",
txtDomain: "foo-a-example.com",
},
{
name: "suffix with dash",
mapper: newaffixNameMapper("", "-foo", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "cname-example-foo.com",
},
{
name: "prefix with dot",
mapper: newaffixNameMapper("foo.", "", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "foo.cname-example.com",
},
{
name: "suffix with dot",
mapper: newaffixNameMapper("", ".foo", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "cname-example.foo.com",
},
{
name: "prefix with multiple dots",
mapper: newaffixNameMapper("foo.bar.", "", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "foo.bar.cname-example.com",
},
{
name: "suffix with multiple dots",
mapper: newaffixNameMapper("", ".foo.bar.test", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "cname-example.foo.bar.test.com",
},
{
name: "templated prefix",
mapper: newaffixNameMapper("%{record_type}-foo", "", ""),
domain: "example.com",
recordType: "A",
txtDomain: "a-fooexample.com",
},
{
name: "templated suffix",
mapper: newaffixNameMapper("", "foo-%{record_type}", ""),
domain: "example.com",
recordType: "A",
txtDomain: "examplefoo-a.com",
},
{
name: "templated prefix with dot",
mapper: newaffixNameMapper("%{record_type}foo.", "", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "cnamefoo.example.com",
},
{
name: "templated suffix with dot",
mapper: newaffixNameMapper("", ".foo%{record_type}", ""),
domain: "example.com",
recordType: "A",
txtDomain: "example.fooa.com",
},
{
name: "templated prefix with multiple dots",
mapper: newaffixNameMapper("bar.%{record_type}.foo.", "", ""),
domain: "example.com",
recordType: "CNAME",
txtDomain: "bar.cname.foo.example.com",
},
{
name: "templated suffix with multiple dots",
mapper: newaffixNameMapper("", ".foo%{record_type}.bar", ""),
domain: "example.com",
recordType: "A",
txtDomain: "example.fooa.bar.com",
},
}

for _, tc := range testCases {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
txtName := tc.mapper.toNewTXTName(tc.domain, tc.recordType)
res, _ := tc.mapper.toEndpointName(txtName)
assert.Equal(t, tc.domain, res)
txtDomain := tc.mapper.toNewTXTName(tc.domain, tc.recordType)
fmt.Println(txtDomain)
assert.Equal(t, tc.txtDomain, txtDomain)
domain, _ := tc.mapper.toEndpointName(txtDomain)
assert.Equal(t, tc.domain, domain)
})
}
}
Expand Down

0 comments on commit e76c681

Please sign in to comment.