More tests

This commit is contained in:
grumbulon 2022-06-29 18:21:43 -04:00
parent c2eab0212a
commit 3467eabfe7
2 changed files with 75 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"os"
"testing"
"git.froth.zone/sam/awl/util"
@ -39,3 +40,21 @@ func TestArgParse(t *testing.T) {
assert.Equal(t, test.want, act)
}
}
func TestQuery(t *testing.T) {
app := prepareCLI()
args := os.Args[0:1]
args = append(args, "--debug")
err := app.Run(args)
assert.Nil(t, err)
}
func TestHTTPS(t *testing.T) {
app := prepareCLI()
args := os.Args[0:1]
args = append(args, "-H")
args = append(args, "@https://cloudflare-dns.com/dns-query")
args = append(args, "git.froth.zone")
err := app.Run(args)
assert.Nil(t, err)
}

56
query/query_test.go Normal file
View file

@ -0,0 +1,56 @@
package query
import (
"testing"
"time"
"git.froth.zone/sam/awl/util"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
)
func TestHTTPS(t *testing.T) {
for i := range queries {
switch i {
case 1:
msg := new(dns.Msg)
testCase := util.Answers{Server: UnmarshallHTTPS(i), Request: dns.TypeAAAA, Name: "localhost"}
msg = msg.SetQuestion(testCase.Name, testCase.Request)
m, rtt, err := ResolveHTTPS(msg, testCase.Name)
assert.Error(t, err)
assert.Nil(t, m)
assert.Equal(t, rtt, time.Duration(0))
case 2:
msg := new(dns.Msg)
testCase := util.Answers{Server: UnmarshallHTTPS(i), Request: dns.TypeAAAA, Name: "localhost"}
msg = msg.SetQuestion(testCase.Name, testCase.Request)
m, rtt, err := ResolveHTTPS(msg, testCase.Name)
assert.Nil(t, err)
assert.Nil(t, m)
assert.Equal(t, rtt, time.Duration(0))
}
}
}
const (
one int = iota
cloudflare
)
var queries = []int{
one,
cloudflare,
}
func UnmarshallHTTPS(i int) string {
switch i {
case 0:
return "::1"
case 1:
return "https://cloudflare-dns.com/dns-query"
}
return ""
}