mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 22:45:46 +03:00
9bd7294fad
Merge in DNS/adguard-home from mv-netutil to master Squashed commit of the following: commit 5698fceed656dca7f8644e7dbd7e1a7fc57a68ce Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Aug 9 15:44:17 2021 +0300 dnsforward: add todos commit 122fb6e3de658b296931e0f608cf24ef85547666 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Aug 9 14:27:46 2021 +0300 all: mv some utilities to netutil
48 lines
819 B
Go
48 lines
819 B
Go
package aghnet
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenerateHostName(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
want string
|
|
ip net.IP
|
|
}{{
|
|
name: "good_ipv4",
|
|
want: "127-0-0-1",
|
|
ip: net.IP{127, 0, 0, 1},
|
|
}, {
|
|
name: "bad_ipv4",
|
|
want: "",
|
|
ip: net.IP{127, 0, 0, 1, 0},
|
|
}, {
|
|
name: "good_ipv6",
|
|
want: "fe00-0000-0000-0000-0000-0000-0000-0001",
|
|
ip: net.ParseIP("fe00::1"),
|
|
}, {
|
|
name: "bad_ipv6",
|
|
want: "",
|
|
ip: net.IP{
|
|
0xff, 0xff, 0xff, 0xff,
|
|
0xff, 0xff, 0xff, 0xff,
|
|
0xff, 0xff, 0xff, 0xff,
|
|
0xff, 0xff, 0xff,
|
|
},
|
|
}, {
|
|
name: "nil",
|
|
want: "",
|
|
ip: nil,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
hostname := GenerateHostname(tc.ip)
|
|
assert.Equal(t, tc.want, hostname)
|
|
})
|
|
}
|
|
}
|