From e76c6813ab6da6edbb1d3d0fcf05a4de2295e8d9 Mon Sep 17 00:00:00 2001 From: Seweryn Chlewicki Date: Fri, 14 Jul 2023 17:48:32 +0100 Subject: [PATCH] Make the tests more verbose --- registry/txt_test.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/registry/txt_test.go b/registry/txt_test.go index 782eb73218..7f6e8f4542 100644 --- a/registry/txt_test.go +++ b/registry/txt_test.go @@ -18,6 +18,7 @@ package registry import ( "context" + "fmt" "reflect" "strings" "testing" @@ -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) @@ -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) }) } }