From 3467eabfe7cf47dcbb62b94de2e372fccfc6e0e1 Mon Sep 17 00:00:00 2001 From: grumbulon Date: Wed, 29 Jun 2022 18:21:43 -0400 Subject: [PATCH] More tests --- cli_test.go | 19 +++++++++++++++ query/query_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 query/query_test.go diff --git a/cli_test.go b/cli_test.go index cf826bb..e621e63 100644 --- a/cli_test.go +++ b/cli_test.go @@ -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) +} diff --git a/query/query_test.go b/query/query_test.go new file mode 100644 index 0000000..852ee9d --- /dev/null +++ b/query/query_test.go @@ -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 "" +}