From f9ee511094e6e09ab2941014c6fcb6cbef212274 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Wed, 8 Nov 2023 18:33:40 +0300 Subject: [PATCH] dnsforward: add tests, todo --- internal/dnsforward/http.go | 2 ++ internal/dnsforward/http_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/dnsforward/http.go b/internal/dnsforward/http.go index c3704a69..a7132000 100644 --- a/internal/dnsforward/http.go +++ b/internal/dnsforward/http.go @@ -811,6 +811,8 @@ func (s *Server) check(req *upstreamJSON, opts *upstream.Options) (result map[st resWG := &sync.WaitGroup{} go func() { for res := range resCh { + // TODO(e.burkov): The servers used for at least two of common, + // private and fallback resolving should be reported separately. if res.status != nil { result[res.ups] = res.status.Error() } else { diff --git a/internal/dnsforward/http_test.go b/internal/dnsforward/http_test.go index dfd1862a..1418a4a1 100644 --- a/internal/dnsforward/http_test.go +++ b/internal/dnsforward/http_test.go @@ -479,6 +479,8 @@ func TestServer_HandleTestUpstreamDNS(t *testing.T) { Host: newLocalUpstreamListener(t, 0, badHandler).String(), }).String() + goodAndBadUps := strings.Join([]string{goodUps, badUps}, " ") + const ( upsTimeout = 100 * time.Millisecond @@ -605,6 +607,29 @@ func TestServer_HandleTestUpstreamDNS(t *testing.T) { `dns: id mismatch`, }, name: "multiple_domain_specific_upstreams", + }, { + body: map[string]any{ + "upstream_dns": []string{"[/domain.example/]/]1.2.3.4"}, + }, + wantResp: map[string]any{ + "[/domain.example/]/]1.2.3.4": `wrong upstream format: ` + + `bad upstream for domain "[/domain.example/]/]1.2.3.4": ` + + `duplicated separator`, + }, + name: "bad_specification", + }, { + body: map[string]any{ + "upstream_dns": []string{"[/domain.example/]" + goodAndBadUps}, + "fallback_dns": []string{"[/domain.example/]" + goodAndBadUps}, + "private_upstream": []string{"[/domain.example/]" + goodAndBadUps}, + }, + wantResp: map[string]any{ + goodUps: "OK", + badUps: `WARNING: couldn't communicate ` + + `with upstream: exchanging with ` + badUps + ` over tcp: ` + + `dns: id mismatch`, + }, + name: "all_different", }} for _, tc := range testCases {