-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in DNS/adguard-home from 1868-rdns-ipv6 to master Updates #2943. Updates #2704. Squashed commit of the following: commit 53d67ec Author: Eugene Burkov <[email protected]> Date: Tue Apr 13 16:18:33 2021 +0300 all: imp code, docs commit 2bc1594 Author: Eugene Burkov <[email protected]> Date: Tue Apr 13 16:09:08 2021 +0300 all: imp code
- Loading branch information
1 parent
773f02c
commit d7b2d63
Showing
7 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters