1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-03 07:45:29 -05:00

test case for write address

This commit is contained in:
Darien Raymond
2018-02-24 02:13:40 +01:00
parent c43a5e7d85
commit a42b4b513e

View File

@@ -10,7 +10,7 @@ import (
. "v2ray.com/ext/assert"
)
func TestAddressParser(t *testing.T) {
func TestAddressReading(t *testing.T) {
assert := With(t)
data := []struct {
@@ -20,6 +20,11 @@ func TestAddressParser(t *testing.T) {
Port net.Port
Error bool
}{
{
Options: []AddressOption{},
Input: []byte{},
Error: true,
},
{
Options: []AddressOption{},
Input: []byte{0, 0, 0, 0, 0},
@@ -65,6 +70,38 @@ func TestAddressParser(t *testing.T) {
} else {
assert(addr, Equals, tc.Address)
assert(port, Equals, tc.Port)
assert(err, IsNil)
}
}
}
func TestAddressWriting(t *testing.T) {
assert := With(t)
data := []struct {
Options []AddressOption
Address net.Address
Port net.Port
Bytes []byte
Error bool
}{
{
Options: []AddressOption{AddressFamilyByte(0x01, net.AddressFamilyIPv4)},
Address: net.LocalHostIP,
Port: net.Port(80),
Bytes: []byte{1, 127, 0, 0, 1, 0, 80},
},
}
for _, tc := range data {
parser := NewAddressParser(tc.Options...)
b := buf.New()
err := parser.WriteAddressPort(b, tc.Address, tc.Port)
if tc.Error {
assert(err, IsNotNil)
} else {
assert(b.Bytes(), Equals, tc.Bytes)
}
}
}