Skip to content

Commit

Permalink
fix: allow time for buffer to complete (HACK)
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jul 12, 2023
1 parent 88ea0b2 commit 31d370f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

const delay = 500 * time.Millisecond

func TestMainQuery(t *testing.T) {
clearOpts()
var out bytes.Buffer
assert.Nil(t, driver([]string{
"-v",
"-q", "example.com",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* TXT "v=spf1 -all"`), out.String())
}

Expand Down Expand Up @@ -47,6 +51,7 @@ func TestMainRawFormat(t *testing.T) {
"-q", "example.com",
"--format=raw",
}, &out))
time.Sleep(delay)
assert.Contains(t, out.String(), "v=spf1 -all")
assert.Contains(t, out.String(), "a.iana-servers.net")
}
Expand All @@ -59,6 +64,7 @@ func TestMainJSONFormat(t *testing.T) {
"-q", "example.com",
"--format=json",
}, &out))
time.Sleep(delay)
assert.Contains(t, out.String(), `"Preference":0,"Mx":"."`)
assert.Contains(t, out.String(), `"Ns":"a.iana-servers.net."`)
assert.Contains(t, out.String(), `"Txt":["v=spf1 -all"]`)
Expand All @@ -72,6 +78,7 @@ func TestMainInvalidOutputFormat(t *testing.T) {
"-q", "example.com",
"--format=invalid",
}, &out)
time.Sleep(delay)
if !(err != nil && strings.Contains(err.Error(), "invalid output format")) {
t.Errorf("invalid output format should throw an error")
}
Expand All @@ -86,6 +93,7 @@ func TestMainParseTypes(t *testing.T) {
"-t", "A",
"-t", "AAAA",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* A .*`), out.String())
assert.Regexp(t, regexp.MustCompile(`example.com. .* AAAA .*`), out.String())
}
Expand All @@ -98,6 +106,7 @@ func TestMainInvalidTypes(t *testing.T) {
"-q", "example.com",
"-t", "INVALID",
}, &out)
time.Sleep(delay)
if !(err != nil && strings.Contains(err.Error(), "INVALID is not a valid RR type")) {
t.Errorf("expected invalid type error, got %+v", err)
}
Expand All @@ -112,6 +121,7 @@ func TestMainInvalidODoHUpstream(t *testing.T) {
"-s", "tls://odoh.cloudflare-dns.com",
"--odoh-proxy", "https://odoh.crypto.sx",
}, &out)
time.Sleep(delay)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "ODoH target must use HTTPS")
}
Expand All @@ -125,6 +135,7 @@ func TestMainInvalidODoHProxy(t *testing.T) {
"-s", "https://odoh.cloudflare-dns.com",
"--odoh-proxy", "tls://odoh1.surfdomeinen.nl",
}, &out)
time.Sleep(delay)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "ODoH proxy must use HTTPS")
}
Expand All @@ -137,6 +148,7 @@ func TestMainReverseQuery(t *testing.T) {
"-x",
"-q", "1.1.1.1",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`1.1.1.1.in-addr.arpa. .* PTR one.one.one.one`), out.String())
}

Expand All @@ -147,6 +159,7 @@ func TestMainInferredQname(t *testing.T) {
"-v",
"example.com",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* A .*`), out.String())
assert.Regexp(t, regexp.MustCompile(`example.com. .* AAAA .*`), out.String())
assert.Regexp(t, regexp.MustCompile(`example.com. .* MX .*`), out.String())
Expand All @@ -160,6 +173,7 @@ func TestMainInferredServer(t *testing.T) {
"-q", "example.com",
"@dns.quad9.net",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* A .*`), out.String())
assert.Regexp(t, regexp.MustCompile(`example.com. .* AAAA .*`), out.String())
assert.Regexp(t, regexp.MustCompile(`example.com. .* MX .*`), out.String())
Expand Down Expand Up @@ -258,6 +272,7 @@ func TestMainTLSQuery(t *testing.T) {
"-t", "A",
"@tls://dns.quad9.net",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* A .*`), out.String())
}

Expand All @@ -270,6 +285,7 @@ func TestMainHTTPSQuery(t *testing.T) {
"-t", "A",
"@https://dns.quad9.net",
}, &out))
time.Sleep(delay)
assert.Regexp(t, regexp.MustCompile(`example.com. .* A .*`), out.String())
}

Expand Down

0 comments on commit 31d370f

Please sign in to comment.