1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 03:25:23 +00:00
v2fly/app/dns/hosts_test.go

53 lines
901 B
Go
Raw Normal View History

package dns_test
import (
"testing"
2018-11-15 10:17:20 +00:00
"github.com/google/go-cmp/cmp"
. "v2ray.com/core/app/dns"
2018-11-15 10:17:20 +00:00
"v2ray.com/core/common"
)
func TestStaticHosts(t *testing.T) {
pb := []*Config_HostMapping{
{
Type: DomainMatchingType_Full,
Domain: "v2ray.com",
Ip: [][]byte{
{1, 1, 1, 1},
},
},
{
Type: DomainMatchingType_Subdomain,
Domain: "v2ray.cn",
Ip: [][]byte{
{2, 2, 2, 2},
},
},
}
hosts, err := NewStaticHosts(pb, nil)
2018-11-15 10:17:20 +00:00
common.Must(err)
{
ips := hosts.LookupIP("v2ray.com")
2018-11-15 10:17:20 +00:00
if len(ips) != 1 {
t.Error("expect 1 IP, but got ", len(ips))
}
if diff := cmp.Diff([]byte(ips[0]), []byte{1, 1, 1, 1}); diff != "" {
t.Error(diff)
}
}
{
ips := hosts.LookupIP("www.v2ray.cn")
2018-11-15 10:17:20 +00:00
if len(ips) != 1 {
t.Error("expect 1 IP, but got ", len(ips))
}
if diff := cmp.Diff([]byte(ips[0]), []byte{2, 2, 2, 2}); diff != "" {
t.Error(diff)
}
}
}