| author | Alberto Bertogli
<albertito@blitiri.com.ar> 2026-08-17 20:06:43 UTC |
| committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2026-08-17 20:06:43 UTC |
| parent | 3110cbeb516a12d62ed526f930a0a009590dca6f |
| internal/dnstest/dns.go => dns_test.go | +8 | -13 |
| spf_test.go | +5 | -7 |
diff --git a/internal/dnstest/dns.go b/dns_test.go similarity index 78% rename from internal/dnstest/dns.go rename to dns_test.go index ad66e3c..2fb348d 100644 --- a/internal/dnstest/dns.go +++ b/dns_test.go @@ -1,10 +1,5 @@ // DNS resolver for testing purposes. -// -// In the future, when go fuzz can make use of _test.go files, we can rename -// this file dns_test.go and remove this extra package entirely. -// Until then, unfortunately this is the most reasonable way to share these -// helpers between go and fuzz tests. -package dnstest +package spf import ( "context" @@ -16,7 +11,7 @@ import ( // // Not exported since this is not part of the public API and only used // internally on tests. -type TestResolver struct { +type testResolver struct { Txt map[string][]string Mx map[string][]*net.MX Ip map[string][]net.IP @@ -25,8 +20,8 @@ type TestResolver struct { Errors map[string]error } -func NewResolver() *TestResolver { - return &TestResolver{ +func newTestResolver() *testResolver { + return &testResolver{ Txt: map[string][]string{}, Mx: map[string][]*net.MX{}, Ip: map[string][]net.IP{}, @@ -41,7 +36,7 @@ var nxDomainErr = &net.DNSError{ IsNotFound: true, } -func (r *TestResolver) LookupTXT(ctx context.Context, domain string) (txts []string, err error) { +func (r *testResolver) LookupTXT(ctx context.Context, domain string) (txts []string, err error) { if ctx.Err() != nil { return nil, ctx.Err() } @@ -56,7 +51,7 @@ func (r *TestResolver) LookupTXT(ctx context.Context, domain string) (txts []str return r.Txt[domain], r.Errors[domain] } -func (r *TestResolver) LookupMX(ctx context.Context, domain string) (mxs []*net.MX, err error) { +func (r *testResolver) LookupMX(ctx context.Context, domain string) (mxs []*net.MX, err error) { if ctx.Err() != nil { return nil, ctx.Err() } @@ -71,7 +66,7 @@ func (r *TestResolver) LookupMX(ctx context.Context, domain string) (mxs []*net. return r.Mx[domain], r.Errors[domain] } -func (r *TestResolver) LookupIPAddr(ctx context.Context, host string) (as []net.IPAddr, err error) { +func (r *testResolver) LookupIPAddr(ctx context.Context, host string) (as []net.IPAddr, err error) { if ctx.Err() != nil { return nil, ctx.Err() } @@ -94,7 +89,7 @@ func ipsToAddrs(ips []net.IP) []net.IPAddr { return as } -func (r *TestResolver) LookupAddr(ctx context.Context, host string) (addrs []string, err error) { +func (r *testResolver) LookupAddr(ctx context.Context, host string) (addrs []string, err error) { if ctx.Err() != nil { return nil, ctx.Err() } diff --git a/spf_test.go b/spf_test.go index caa76bc..8aa5cae 100644 --- a/spf_test.go +++ b/spf_test.go @@ -5,12 +5,10 @@ import ( "net" "strings" "testing" - - "blitiri.com.ar/go/spf/internal/dnstest" ) -func NewDefaultResolver() *dnstest.TestResolver { - dns := dnstest.NewResolver() +func NewDefaultResolver() *testResolver { + dns := newTestResolver() defaultResolver = dns return dns } @@ -742,8 +740,8 @@ func TestWithContext(t *testing.T) { func TestWithResolver(t *testing.T) { // Use a custom resolver, making sure it's different from the default. - defaultResolver = dnstest.NewResolver() - dns := dnstest.NewResolver() + defaultResolver = newTestResolver() + dns := newTestResolver() defaultTrace = t.Logf dns.Txt["domain1"] = []string{"v=spf1 include:domain2"} @@ -759,7 +757,7 @@ func TestWithResolver(t *testing.T) { // Test some corner cases when resolver.LookupIPAddr returns an invalid // address. This can happen if using a buggy custom resolver. func TestBadResolverResponse(t *testing.T) { - dns := dnstest.NewResolver() + dns := newTestResolver() defaultTrace = t.Logf // When LookupIPAddr returns an invalid ip, for an "a" field.