awl/query/query_test.go
2022-06-29 18:21:43 -04:00

57 lines
1.1 KiB
Go

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 ""
}