2016-01-15 07:17:04 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package net_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
. "v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-01-15 07:17:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIPParsing(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-01-15 07:17:04 -05:00
|
|
|
|
|
|
|
rawJson := "\"8.8.8.8\""
|
2016-08-26 18:04:35 -04:00
|
|
|
var address AddressPB
|
2016-01-15 07:17:04 -05:00
|
|
|
err := json.Unmarshal([]byte(rawJson), &address)
|
|
|
|
assert.Error(err).IsNil()
|
2016-08-26 18:04:35 -04:00
|
|
|
assert.Bytes(address.GetIp()).Equals([]byte{8, 8, 8, 8})
|
2016-01-15 07:17:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDomainParsing(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-01-15 07:17:04 -05:00
|
|
|
|
|
|
|
rawJson := "\"v2ray.com\""
|
2016-08-26 18:04:35 -04:00
|
|
|
var address AddressPB
|
2016-01-15 07:17:04 -05:00
|
|
|
err := json.Unmarshal([]byte(rawJson), &address)
|
|
|
|
assert.Error(err).IsNil()
|
2016-08-26 18:04:35 -04:00
|
|
|
assert.String(address.GetDomain()).Equals("v2ray.com")
|
2016-01-15 07:17:04 -05:00
|
|
|
}
|
2016-02-04 05:43:04 -05:00
|
|
|
|
2016-02-04 05:47:57 -05:00
|
|
|
func TestInvalidAddressJson(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-02-04 05:43:04 -05:00
|
|
|
|
|
|
|
rawJson := "1234"
|
2016-08-26 18:04:35 -04:00
|
|
|
var address AddressPB
|
2016-02-04 05:43:04 -05:00
|
|
|
err := json.Unmarshal([]byte(rawJson), &address)
|
|
|
|
assert.Error(err).IsNotNil()
|
|
|
|
}
|