| 1 | package dns_testscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.15 testing/" |
| 5 | |
| 6 | "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/" |
| 7 | . "v2ray.com/core/app/dnsscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/" |
| 8 | "v2ray.com/core/commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/" |
| 9 | "v2ray.com/core/common/netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/" |
| 10 | ) |
| 11 | |
| 12 | func TestStaticHostsscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns_test`/TestStaticHosts().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 13 | pb := []*Config_HostMappingscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#{ |
| 14 | { |
| 15 | Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Type.: DomainMatchingType_Fullscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/DomainMatchingType_Full., |
| 16 | Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Domain.: "v2ray.com", |
| 17 | Ipscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Ip.: [][]byte{ |
| 18 | {1, 1, 1, 1}, |
| 19 | }, |
| 20 | }, |
| 21 | { |
| 22 | Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Type.: DomainMatchingType_Subdomainscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/DomainMatchingType_Subdomain., |
| 23 | Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Domain.: "v2ray.cn", |
| 24 | Ipscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Ip.: [][]byte{ |
| 25 | {2, 2, 2, 2}, |
| 26 | }, |
| 27 | }, |
| 28 | { |
| 29 | Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Type.: DomainMatchingType_Subdomainscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/DomainMatchingType_Subdomain., |
| 30 | Domainscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Domain.: "baidu.com", |
| 31 | Ipscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/Config_HostMapping#Ip.: [][]byte{ |
| 32 | {127, 0, 0, 1}, |
| 33 | }, |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | hosts, err := NewStaticHostsscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/NewStaticHosts().(pb, nil) |
| 38 | commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.Mustscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Must().(err) |
| 39 | |
| 40 | { |
| 41 | ips := hosts.Lookupscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/StaticHosts#Lookup().("v2ray.com", IPOptionscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#{ |
| 42 | IPv4Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv4Enable.: true, |
| 43 | IPv6Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv6Enable.: true, |
| 44 | }) |
| 45 | if len(ips) != 1 { |
| 46 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("expect 1 IP, but got ", len(ips)) |
| 47 | } |
| 48 | if diff := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().([]byte(ips[0].IPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Address#IP.()), []byte{1, 1, 1, 1}); diff != "" { |
| 49 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().(diff) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | { |
| 54 | ips := hosts.Lookupscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/StaticHosts#Lookup().("www.v2ray.cn", IPOptionscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#{ |
| 55 | IPv4Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv4Enable.: true, |
| 56 | IPv6Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv6Enable.: true, |
| 57 | }) |
| 58 | if len(ips) != 1 { |
| 59 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("expect 1 IP, but got ", len(ips)) |
| 60 | } |
| 61 | if diff := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().([]byte(ips[0].IPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Address#IP.()), []byte{2, 2, 2, 2}); diff != "" { |
| 62 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().(diff) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | ips := hosts.Lookupscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/StaticHosts#Lookup().("baidu.com", IPOptionscip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#{ |
| 68 | IPv4Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv4Enable.: false, |
| 69 | IPv6Enablescip-go gomod v2ray.com/core . `v2ray.com/core/app/dns`/IPOption#IPv6Enable.: true, |
| 70 | }) |
| 71 | if len(ips) != 1 { |
| 72 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("expect 1 IP, but got ", len(ips)) |
| 73 | } |
| 74 | if diff := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().([]byte(ips[0].IPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Address#IP.()), []byte(netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/.LocalHostIPv6scip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/LocalHostIPv6..IPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Address#IP.())); diff != "" { |
| 75 | t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().(diff) |
| 76 | } |
| 77 | } |
| 78 | } |