Pull request: 1868 fix rdns

Merge in DNS/adguard-home from 1868-rdns-ipv6 to master

Updates #2943.
Updates #2704.

Squashed commit of the following:

commit 53d67ecf17ed4f9c544344288b58f3596c7246e2
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Tue Apr 13 16:18:33 2021 +0300

    all: imp code, docs

commit 2bc15941b87f92b6fa0a7568538e02700a4385a3
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Tue Apr 13 16:09:08 2021 +0300

    all: imp code
This commit is contained in:
Eugene Burkov
2021-04-13 16:23:36 +03:00
parent 773f02cf7d
commit d7b2d63e4c
7 changed files with 85 additions and 8 deletions

View File

@@ -16,7 +16,7 @@ import (
// testTLSConn is a tlsConn for tests.
type testTLSConn struct {
// Conn is embedded here simply to make testTLSConn a net.Conn without
// acctually implementing all methods.
// actually implementing all methods.
net.Conn
serverName string

View File

@@ -18,7 +18,7 @@ import (
// testQueryLog is a simple querylog.QueryLog implementation for tests.
type testQueryLog struct {
// QueryLog is embedded here simply to make testQueryLog
// a querylog.QueryLog without acctually implementing all methods.
// a querylog.QueryLog without actually implementing all methods.
querylog.QueryLog
lastParams querylog.AddParams
@@ -32,7 +32,7 @@ func (l *testQueryLog) Add(p querylog.AddParams) {
// testStats is a simple stats.Stats implementation for tests.
type testStats struct {
// Stats is embedded here simply to make testStats a stats.Stats without
// acctually implementing all methods.
// actually implementing all methods.
stats.Stats
lastEntry stats.Entry

View File

@@ -0,0 +1,60 @@
package dnsforward
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
// fakeAddr is a mock implementation of net.Addr interface to simplify testing.
type fakeAddr struct {
// Addr is embedded here simply to make fakeAddr a net.Addr without
// actually implementing all methods.
net.Addr
}
func TestIPFromAddr(t *testing.T) {
supIPv4 := net.IP{1, 2, 3, 4}
supIPv6 := net.ParseIP("2a00:1450:400c:c06::93")
testCases := []struct {
name string
addr net.Addr
want net.IP
}{{
name: "ipv4_tcp",
addr: &net.TCPAddr{
IP: supIPv4,
},
want: supIPv4,
}, {
name: "ipv6_tcp",
addr: &net.TCPAddr{
IP: supIPv6,
},
want: supIPv6,
}, {
name: "ipv4_udp",
addr: &net.UDPAddr{
IP: supIPv4,
},
want: supIPv4,
}, {
name: "ipv6_udp",
addr: &net.UDPAddr{
IP: supIPv6,
},
want: supIPv6,
}, {
name: "non-ip_addr",
addr: &fakeAddr{},
want: nil,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, IPFromAddr(tc.addr))
})
}
}