2016-10-17 08:35:13 -04:00
|
|
|
package conf_test
|
2016-05-16 12:19:55 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
v2net "v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-10-17 08:35:13 -04:00
|
|
|
. "v2ray.com/core/tools/conf"
|
2016-05-16 12:19:55 -04:00
|
|
|
)
|
|
|
|
|
2016-10-17 08:35:13 -04:00
|
|
|
func TestDnsConfigParsing(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-05-16 12:19:55 -04:00
|
|
|
|
|
|
|
rawJson := `{
|
|
|
|
"servers": ["8.8.8.8"]
|
|
|
|
}`
|
|
|
|
|
2016-10-17 08:35:13 -04:00
|
|
|
jsonConfig := new(DnsConfig)
|
|
|
|
err := json.Unmarshal([]byte(rawJson), jsonConfig)
|
2016-05-16 12:19:55 -04:00
|
|
|
assert.Error(err).IsNil()
|
2016-10-17 08:35:13 -04:00
|
|
|
|
|
|
|
config := jsonConfig.Build()
|
2016-05-16 12:19:55 -04:00
|
|
|
assert.Int(len(config.NameServers)).Equals(1)
|
2016-09-20 10:05:35 -04: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 12:19:55 -04:00
|
|
|
}
|