2018-06-26 16:34:05 -04:00
|
|
|
package dns_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "v2ray.com/core/app/dns"
|
|
|
|
. "v2ray.com/ext/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStaticHosts(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
pb := []*Config_HostMapping{
|
|
|
|
{
|
2018-08-24 15:51:03 -04:00
|
|
|
Type: DomainMatchingType_Full,
|
2018-06-26 16:34:05 -04:00
|
|
|
Domain: "v2ray.com",
|
|
|
|
Ip: [][]byte{
|
|
|
|
{1, 1, 1, 1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-08-24 15:51:03 -04:00
|
|
|
Type: DomainMatchingType_Subdomain,
|
2018-06-26 16:34:05 -04:00
|
|
|
Domain: "v2ray.cn",
|
|
|
|
Ip: [][]byte{
|
|
|
|
{2, 2, 2, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
hosts, err := NewStaticHosts(pb, nil)
|
|
|
|
assert(err, IsNil)
|
|
|
|
|
|
|
|
{
|
|
|
|
ips := hosts.LookupIP("v2ray.com")
|
|
|
|
assert(len(ips), Equals, 1)
|
|
|
|
assert([]byte(ips[0]), Equals, []byte{1, 1, 1, 1})
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ips := hosts.LookupIP("www.v2ray.cn")
|
|
|
|
assert(len(ips), Equals, 1)
|
|
|
|
assert([]byte(ips[0]), Equals, []byte{2, 2, 2, 2})
|
|
|
|
}
|
|
|
|
}
|