test: Add retries to all tests (#121)
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #121
Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
This commit is contained in:
Sam Therapy 2022-09-28 17:51:35 +00:00
parent 0a371cd335
commit c053c077c8
Signed by: Froth Git
GPG key ID: 5D8CD75CC6B79913
5 changed files with 62 additions and 20 deletions

View file

@ -187,16 +187,26 @@ func TestRealPrint(t *testing.T) {
t.Run("", func(t *testing.T) {
t.Parallel()
resp, err := query.CreateQuery(test)
var (
res util.Response
err error
)
for i := 0; i <= test.Request.Retries; i++ {
res, err = query.CreateQuery(test)
if err == nil {
break
}
}
assert.NilError(t, err)
if test.JSON || test.XML || test.YAML {
str := ""
str, err = query.PrintSpecial(resp, test)
str, err = query.PrintSpecial(res, test)
assert.NilError(t, err)
assert.Assert(t, str != "")
}
str, err := query.ToString(resp, test)
str, err := query.ToString(res, test)
assert.NilError(t, err)
assert.Assert(t, str != "")
})

View file

@ -3,10 +3,12 @@
package resolvers_test
import (
"errors"
"testing"
"git.froth.zone/sam/awl/pkg/query"
"git.froth.zone/sam/awl/pkg/util"
"github.com/ameshkov/dnscrypt/v2"
"github.com/miekg/dns"
"gotest.tools/v3/assert"
)
@ -69,7 +71,17 @@ func TestDNSCrypt(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
res, err := query.CreateQuery(test.opts)
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, dnscrypt.ErrInvalidDNSStamp) {
break
}
}
if err == nil {
assert.Assert(t, res != util.Response{})
} else {

View file

@ -6,6 +6,7 @@ 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"
@ -76,13 +77,16 @@ func TestHTTPS(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
resolver, err := resolvers.LoadResolver(test.opts)
assert.NilError(t, err)
msg := new(dns.Msg)
msg.SetQuestion(test.opts.Request.Name, test.opts.Request.Type)
// msg = msg.SetQuestion(testCase.Name, testCase.Type)
res, err := resolver.LookUp(msg)
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)

View file

@ -6,7 +6,7 @@ import (
"testing"
"time"
"git.froth.zone/sam/awl/pkg/resolvers"
"git.froth.zone/sam/awl/pkg/query"
"git.froth.zone/sam/awl/pkg/util"
"github.com/miekg/dns"
"gotest.tools/v3/assert"
@ -74,6 +74,7 @@ func TestQuic(t *testing.T) {
Type: dns.TypeA,
Name: "git.froth.zone",
Timeout: 10 * time.Millisecond,
Retries: 0,
},
},
},
@ -85,13 +86,16 @@ func TestQuic(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
resolver, err := resolvers.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)
var (
res util.Response
err error
)
for i := 0; i <= test.opts.Request.Retries; i++ {
res, err = query.CreateQuery(test.opts)
if err == nil {
break
}
}
if err == nil {
assert.NilError(t, err)

View file

@ -3,12 +3,14 @@
package resolvers_test
import (
"errors"
"os"
"testing"
"time"
"git.froth.zone/sam/awl/pkg/query"
"git.froth.zone/sam/awl/pkg/util"
"github.com/ameshkov/dnscrypt/v2"
"github.com/miekg/dns"
"gotest.tools/v3/assert"
)
@ -116,7 +118,17 @@ func TestResolve(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
res, err := query.CreateQuery(test.opts)
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, dnscrypt.ErrInvalidDNSStamp) {
break
}
}
if err == nil {
assert.NilError(t, err)
assert.Assert(t, res != util.Response{})