mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-25 19:45:38 -05:00
Add Port as a type
This commit is contained in:
@@ -11,14 +11,14 @@ func TestIPv4Address(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
ip := []byte{byte(1), byte(2), byte(3), byte(4)}
|
||||
port := uint16(80)
|
||||
addr := IPAddress(ip, port)
|
||||
port := NewPort(80)
|
||||
addr := IPAddress(ip, port.Value())
|
||||
|
||||
assert.Bool(addr.IsIPv4()).IsTrue()
|
||||
assert.Bool(addr.IsIPv6()).IsFalse()
|
||||
assert.Bool(addr.IsDomain()).IsFalse()
|
||||
assert.Bytes(addr.IP()).Equals(ip)
|
||||
assert.Uint16(addr.Port()).Equals(port)
|
||||
assert.Uint16(addr.Port().Value()).Equals(port.Value())
|
||||
assert.String(addr.String()).Equals("1.2.3.4:80")
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ func TestIPv6Address(t *testing.T) {
|
||||
byte(1), byte(2), byte(3), byte(4),
|
||||
byte(1), byte(2), byte(3), byte(4),
|
||||
}
|
||||
port := uint16(443)
|
||||
addr := IPAddress(ip, port)
|
||||
port := NewPort(443)
|
||||
addr := IPAddress(ip, port.Value())
|
||||
|
||||
assert.Bool(addr.IsIPv6()).IsTrue()
|
||||
assert.Bool(addr.IsIPv4()).IsFalse()
|
||||
assert.Bool(addr.IsDomain()).IsFalse()
|
||||
assert.Bytes(addr.IP()).Equals(ip)
|
||||
assert.Uint16(addr.Port()).Equals(port)
|
||||
assert.Uint16(addr.Port().Value()).Equals(port.Value())
|
||||
assert.String(addr.String()).Equals("[102:304:102:304:102:304:102:304]:443")
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ func TestDomainAddress(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
domain := "v2ray.com"
|
||||
port := uint16(443)
|
||||
addr := DomainAddress(domain, port)
|
||||
port := NewPort(443)
|
||||
addr := DomainAddress(domain, port.Value())
|
||||
|
||||
assert.Bool(addr.IsDomain()).IsTrue()
|
||||
assert.Bool(addr.IsIPv4()).IsFalse()
|
||||
assert.Bool(addr.IsIPv6()).IsFalse()
|
||||
assert.String(addr.Domain()).Equals(domain)
|
||||
assert.Uint16(addr.Port()).Equals(port)
|
||||
assert.Uint16(addr.Port().Value()).Equals(port.Value())
|
||||
assert.String(addr.String()).Equals("v2ray.com:443")
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ func TestNetIPv4Address(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
ip := net.IPv4(1, 2, 3, 4)
|
||||
port := uint16(80)
|
||||
addr := IPAddress(ip, port)
|
||||
port := NewPort(80)
|
||||
addr := IPAddress(ip, port.Value())
|
||||
assert.Bool(addr.IsIPv4()).IsTrue()
|
||||
assert.String(addr.String()).Equals("1.2.3.4:80")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user