You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/net/address_json_test.go

46 lines
1.2 KiB

// +build json
package net_test
import (
"encoding/json"
"net"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestIPParsing(t *testing.T) {
9 years ago
assert := assert.On(t)
rawJson := "\"8.8.8.8\""
var address AddressJson
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNil()
assert.Bool(address.Address.Family().Either(AddressFamilyIPv4)).IsTrue()
assert.Bool(address.Address.Family().Either(AddressFamilyDomain)).IsFalse()
assert.Bool(address.Address.IP().Equal(net.ParseIP("8.8.8.8"))).IsTrue()
}
func TestDomainParsing(t *testing.T) {
9 years ago
assert := assert.On(t)
rawJson := "\"v2ray.com\""
var address AddressJson
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNil()
assert.Bool(address.Address.Family().Either(AddressFamilyIPv4)).IsFalse()
assert.Bool(address.Address.Family().Either(AddressFamilyDomain)).IsTrue()
9 years ago
assert.String(address.Address.Domain()).Equals("v2ray.com")
}
9 years ago
func TestInvalidAddressJson(t *testing.T) {
9 years ago
assert := assert.On(t)
rawJson := "1234"
var address AddressJson
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNotNil()
}