v2ray-core/tools/conf/dns_test.go

30 lines
665 B
Go
Raw Normal View History

2016-10-17 14:35:13 +02:00
package conf_test
2016-05-16 09:19:55 -07:00
import (
"encoding/json"
"testing"
2016-08-20 20:55:45 +02:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
2016-10-17 14:35:13 +02:00
. "v2ray.com/core/tools/conf"
2016-05-16 09:19:55 -07:00
)
2016-10-17 14:35:13 +02:00
func TestDnsConfigParsing(t *testing.T) {
2016-05-24 21:55:46 +02:00
assert := assert.On(t)
2016-05-16 09:19:55 -07:00
rawJson := `{
"servers": ["8.8.8.8"]
}`
2016-10-17 14:35:13 +02:00
jsonConfig := new(DnsConfig)
err := json.Unmarshal([]byte(rawJson), jsonConfig)
2016-05-16 09:19:55 -07:00
assert.Error(err).IsNil()
2016-10-17 14:35:13 +02:00
config := jsonConfig.Build()
2016-05-16 09:19:55 -07:00
assert.Int(len(config.NameServers)).Equals(1)
2016-09-20 16:05:35 +02:00
dest := config.NameServers[0].AsDestination()
assert.Destination(dest).IsUDP()
assert.Address(dest.Address).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
assert.Port(dest.Port).Equals(v2net.Port(53))
2016-05-16 09:19:55 -07:00
}