awl/query/QUIC_test.go
Sam Therapy 8a3afa261a
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
refactor: make more tests table driven
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-09-21 14:07:00 +02:00

104 lines
1.9 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package query_test
import (
"testing"
"time"
"git.froth.zone/sam/awl/query"
"git.froth.zone/sam/awl/util"
"github.com/miekg/dns"
"gotest.tools/v3/assert"
)
func TestQuic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
opts util.Options
}{
{
"Valid",
util.Options{
QUIC: true,
Logger: util.InitLogger(0),
Request: util.Request{
Server: "dns.adguard.com",
Type: dns.TypeNS,
Port: 853,
Timeout: 750 * time.Millisecond,
Retries: 3,
},
},
},
{
"Bad domain",
util.Options{
QUIC: true,
Logger: util.InitLogger(0),
Request: util.Request{
Server: "dns.//./,,adguard\a.com",
Port: 853,
Type: dns.TypeA,
Name: "git.froth.zone",
Timeout: 100 * time.Millisecond,
Retries: 0,
},
},
},
{
"Not canonical",
util.Options{
QUIC: true,
Logger: util.InitLogger(0),
Request: util.Request{
Server: "dns.adguard.com",
Port: 853,
Type: dns.TypeA,
Name: "git.froth.zone",
Timeout: 100 * time.Millisecond,
Retries: 0,
},
},
},
{
"Invalid query domain",
util.Options{
QUIC: true,
Logger: util.InitLogger(0),
Request: util.Request{
Server: "example.com",
Port: 853,
Type: dns.TypeA,
Name: "git.froth.zone",
Timeout: 10 * time.Millisecond,
},
},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
resolver, err := query.LoadResolver(test.opts)
assert.NilError(t, err)
msg := new(dns.Msg)
msg.SetQuestion(test.opts.Request.Name, test.opts.Request.Type)
res, err := resolver.LookUp(msg)
if err == nil {
assert.NilError(t, err)
assert.Assert(t, res != util.Response{})
} else {
assert.Assert(t, res == util.Response{})
}
})
}
}