1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/app/dns/internal/dns_test.go

34 lines
956 B
Go
Raw Normal View History

2016-01-31 11:01:28 -05:00
package internal_test
2015-12-06 05:00:10 -05:00
import (
"net"
"testing"
2016-01-31 11:01:28 -05:00
. "github.com/v2ray/v2ray-core/app/dns/internal"
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"
2016-01-15 09:23:12 -05:00
"github.com/v2ray/v2ray-core/common/serial"
2015-12-06 05:00:10 -05:00
v2testing "github.com/v2ray/v2ray-core/testing"
)
func TestDnsAdd(t *testing.T) {
v2testing.Current(t)
domain := "v2ray.com"
2016-01-31 11:01:28 -05:00
cache := NewCache(&CacheConfig{
2016-01-15 09:23:12 -05:00
TrustedTags: map[serial.StringLiteral]bool{
serial.StringLiteral("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}))
}