Sam
81da49093d
All checks were successful
continuous-integration/drone/push Build is passing
Instead of copying the opts struct every time it gets passed around, it should be created once and passed through reference. This should reduce memory utilization, unfortunately I cannot test it since this program runs so fast pprof won't report anything useful. I think I found all of them 🙂 Co-authored-by: Sam Therapy <sam@samtherapy.net> Reviewed-on: #132 Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
103 lines
2 KiB
Go
103 lines
2 KiB
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package resolvers_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.froth.zone/sam/awl/pkg/query"
|
|
"git.froth.zone/sam/awl/pkg/resolvers"
|
|
"git.froth.zone/sam/awl/pkg/util"
|
|
"github.com/miekg/dns"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestHTTPS(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
//nolint:govet // I could not be assed to refactor this, and it is only for tests
|
|
tests := []struct {
|
|
name string
|
|
opts *util.Options
|
|
}{
|
|
{
|
|
"Good",
|
|
&util.Options{
|
|
HTTPS: true,
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "https://dns9.quad9.net/dns-query",
|
|
Type: dns.TypeA,
|
|
Name: "git.froth.zone.",
|
|
Retries: 3,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"404",
|
|
&util.Options{
|
|
HTTPS: true,
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "https://dns9.quad9.net/dns",
|
|
Type: dns.TypeA,
|
|
Name: "git.froth.zone.",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"Bad request domain",
|
|
&util.Options{
|
|
HTTPS: true,
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "dns9.quad9.net/dns-query",
|
|
Type: dns.TypeA,
|
|
Name: "git.froth.zone",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"Bad server domain",
|
|
&util.Options{
|
|
HTTPS: true,
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "dns9..quad9.net/dns-query",
|
|
Type: dns.TypeA,
|
|
Name: "git.froth.zone.",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
test := test
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
res util.Response
|
|
err error
|
|
)
|
|
for i := 0; i <= test.opts.Request.Retries; i++ {
|
|
res, err = query.CreateQuery(test.opts)
|
|
if err == nil || errors.Is(err, &resolvers.ErrHTTPStatus{}) {
|
|
break
|
|
}
|
|
}
|
|
|
|
if err == nil {
|
|
assert.NilError(t, err)
|
|
assert.Assert(t, res != util.Response{})
|
|
} else {
|
|
if errors.Is(err, &resolvers.ErrHTTPStatus{}) {
|
|
assert.ErrorContains(t, err, "404")
|
|
}
|
|
assert.Equal(t, res, util.Response{})
|
|
}
|
|
})
|
|
}
|
|
}
|