From f9b31afa48a57603bf0a97e647960180d5337e27 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Wed, 16 Sep 2015 22:19:42 +0200 Subject: [PATCH] Test case for address --- net/address_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ net/vmess/config.go | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 net/address_test.go diff --git a/net/address_test.go b/net/address_test.go new file mode 100644 index 000000000..a495723fa --- /dev/null +++ b/net/address_test.go @@ -0,0 +1,51 @@ +package net + +import ( + "testing" + + "github.com/v2ray/v2ray-core/testing/unit" +) + +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) + + assert.Byte(addr.Type).Equals(AddrTypeIP) + assert.Bool(addr.IsIPv4()).IsTrue() + assert.Bytes(addr.IP).Equals(ip) + assert.Uint16(addr.Port).Equals(port) +} + +func TestIPv6Address(t *testing.T) { + assert := unit.Assert(t) + + ip := []byte{ + byte(1), byte(2), byte(3), byte(4), + byte(1), byte(2), byte(3), byte(4), + byte(1), byte(2), byte(3), byte(4), + byte(1), byte(2), byte(3), byte(4), + } + port := uint16(443) + addr := IPAddress(ip, port) + + assert.Byte(addr.Type).Equals(AddrTypeIP) + assert.Bool(addr.IsIPv6()).IsTrue() + assert.Bytes(addr.IP).Equals(ip) + assert.Uint16(addr.Port).Equals(port) +} + +func TestDomainAddress(t *testing.T) { + assert := unit.Assert(t) + + domain := "v2ray.com" + port := uint16(443) + addr := DomainAddress(domain, port) + + assert.Byte(addr.Type).Equals(AddrTypeDomain) + assert.Bool(addr.IsDomain()).IsTrue() + assert.String(addr.Domain).Equals(domain) + assert.Uint16(addr.Port).Equals(port) +} diff --git a/net/vmess/config.go b/net/vmess/config.go index 2cf5d149b..1beb4bb33 100644 --- a/net/vmess/config.go +++ b/net/vmess/config.go @@ -17,7 +17,7 @@ type VMessUser struct { func (u *VMessUser) ToUser() (core.User, error) { id, err := core.NewID(u.Id) return core.User{ - Id: id, + Id: id, }, err }