From ccca73513acda479c7591fd6b33f308a032ccf13 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Thu, 26 Dec 2024 14:41:59 +0300 Subject: [PATCH] all: imp docs --- README.md | 2 +- internal/cmd/args.go | 9 ++++----- internal/handler/default_internal_test.go | 7 ++++++- .../handler/testdata/TestDefault_resolveFromHosts/hosts | 2 +- .../testdata/TestDefault_resolveFromHosts/hosts.txt | 3 +++ 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 internal/handler/testdata/TestDefault_resolveFromHosts/hosts.txt diff --git a/README.md b/README.md index c29624d07..303abc1d2 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Application Options: --private-subnets= Private subnets to use for reverse DNS lookups of private addresses --bogus-nxdomain= Transform the responses containing at least a single IP that matches specified addresses and CIDRs into NXDOMAIN. Can be specified multiple times. - --hosts-files= List of paths to the hosts files relative to the root, can be specified multiple times + --hosts-files= List of paths to the hosts files, can be specified multiple times --timeout= Timeout for outbound DNS queries to remote upstream servers in a human-readable form (default: 10s) --cache-min-ttl= Minimum TTL value for DNS entries, in seconds. Capped at 3600. Artificially extending TTLs should only be done with careful consideration. diff --git a/internal/cmd/args.go b/internal/cmd/args.go index 4626fef1a..adeca257e 100644 --- a/internal/cmd/args.go +++ b/internal/cmd/args.go @@ -221,11 +221,10 @@ var commandLineOptions = []*commandLineOption{ valueType: "subnet", }, hostsFilesIdx: { - description: "List of paths to the hosts files relative to the root, can be specified " + - "multiple times.", - long: "hosts-files", - short: "", - valueType: "path", + description: "List of paths to the hosts files, can be specified multiple times.", + long: "hosts-files", + short: "", + valueType: "path", }, timeoutIdx: { description: "Timeout for outbound DNS queries to remote upstream servers in a " + diff --git a/internal/handler/default_internal_test.go b/internal/handler/default_internal_test.go index 3d5ce45f9..1914bc43b 100644 --- a/internal/handler/default_internal_test.go +++ b/internal/handler/default_internal_test.go @@ -5,6 +5,7 @@ import ( "net/netip" "os" "path" + "path/filepath" "testing" "time" @@ -84,7 +85,11 @@ func TestDefault_resolveFromHosts(t *testing.T) { // TODO(e.burkov): Use the one from [dnsproxytest]. messages := dnsmsg.DefaultMessageConstructor{} - strg, err := ReadHosts([]string{path.Join("testdata", t.Name(), "hosts")}) + relPath := path.Join("testdata", t.Name(), "hosts") + absPath, err := filepath.Abs(path.Join("testdata", t.Name(), "hosts.txt")) + require.NoError(t, err) + + strg, err := ReadHosts([]string{absPath, relPath}) require.NoError(t, err) hdlr, err := NewDefault(&DefaultConfig{ diff --git a/internal/handler/testdata/TestDefault_resolveFromHosts/hosts b/internal/handler/testdata/TestDefault_resolveFromHosts/hosts index 9a081820b..5ecc062bd 100644 --- a/internal/handler/testdata/TestDefault_resolveFromHosts/hosts +++ b/internal/handler/testdata/TestDefault_resolveFromHosts/hosts @@ -1,3 +1,3 @@ 1.2.3.4 ipv4.domain.example -2001:db8::1 ipv6.domain.example +# 2001:db8::1 ipv6.domain.example # comment diff --git a/internal/handler/testdata/TestDefault_resolveFromHosts/hosts.txt b/internal/handler/testdata/TestDefault_resolveFromHosts/hosts.txt new file mode 100644 index 000000000..2b38eb1ba --- /dev/null +++ b/internal/handler/testdata/TestDefault_resolveFromHosts/hosts.txt @@ -0,0 +1,3 @@ +# 1.2.3.4 ipv4.domain.example +2001:db8::1 ipv6.domain.example +# comment