1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-12 23:18:36 -04:00
v2fly/app/dns/dns_test.go

34 lines
932 B
Go
Raw Normal View History

2015-12-06 05:00:10 -05:00
package dns_test
import (
"net"
"testing"
"github.com/v2ray/v2ray-core/app/dns"
dnstesting "github.com/v2ray/v2ray-core/app/dns/testing"
2015-12-10 17:55:39 -05:00
apptesting "github.com/v2ray/v2ray-core/app/testing"
2015-12-06 05:00:10 -05:00
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
v2testing "github.com/v2ray/v2ray-core/testing"
)
func TestDnsAdd(t *testing.T) {
v2testing.Current(t)
domain := "v2ray.com"
cache := dns.NewCache(&dnstesting.CacheConfig{
TrustedTags: map[string]bool{
"testtag": true,
},
})
2015-12-10 17:55:39 -05:00
ip := cache.Get(&apptesting.Context{}, domain)
2015-12-06 05:00:10 -05:00
netassert.IP(ip).IsNil()
cache.Add(&apptesting.Context{CallerTagValue: "notvalidtag"}, domain, []byte{1, 2, 3, 4})
ip = cache.Get(&apptesting.Context{}, domain)
netassert.IP(ip).IsNil()
cache.Add(&apptesting.Context{CallerTagValue: "testtag"}, domain, []byte{1, 2, 3, 4})
2015-12-10 17:55:39 -05:00
ip = cache.Get(&apptesting.Context{}, domain)
2015-12-06 05:00:10 -05:00
netassert.IP(ip).Equals(net.IP([]byte{1, 2, 3, 4}))
}