From c54c0218e02a342f66c5333a0a5505959fbf6bab Mon Sep 17 00:00:00 2001 From: v2ray Date: Sun, 6 Dec 2015 20:38:01 +0100 Subject: [PATCH] simplify test --- common/net/json/portrange.go | 12 ++++++------ common/net/testing/port.go | 2 +- shell/point/json/json_test.go | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/net/json/portrange.go b/common/net/json/portrange.go index 5768206c8..c72aa0774 100644 --- a/common/net/json/portrange.go +++ b/common/net/json/portrange.go @@ -35,8 +35,8 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { log.Error("Invalid port [%s]", string(data)) return InvalidPortRange } - this.from = v2net.Port(uint16(maybeint)) - this.to = v2net.Port(uint16(maybeint)) + this.from = v2net.Port(maybeint) + this.to = v2net.Port(maybeint) return nil } @@ -50,8 +50,8 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { log.Error("Invalid from port %s", pair[0]) return InvalidPortRange } - this.from = v2net.Port(uint16(value)) - this.to = v2net.Port(uint16(value)) + this.from = v2net.Port(value) + this.to = v2net.Port(value) return nil } else if len(pair) == 2 { from, err := strconv.Atoi(pair[0]) @@ -59,14 +59,14 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { log.Error("Invalid from port %s", pair[0]) return InvalidPortRange } - this.from = v2net.Port(uint16(from)) + this.from = v2net.Port(from) to, err := strconv.Atoi(pair[1]) if err != nil || to <= 0 || to >= 65535 { log.Error("Invalid to port %s", pair[1]) return InvalidPortRange } - this.to = v2net.Port(uint16(to)) + this.to = v2net.Port(to) if this.from > this.to { log.Error("Invalid port range %d -> %d", this.from, this.to) diff --git a/common/net/testing/port.go b/common/net/testing/port.go index ebdf370da..21fce1771 100644 --- a/common/net/testing/port.go +++ b/common/net/testing/port.go @@ -11,5 +11,5 @@ var ( ) func PickPort() v2net.Port { - return v2net.Port(uint16(atomic.AddInt32(&port, 1))) + return v2net.Port(atomic.AddInt32(&port, 1)) } diff --git a/shell/point/json/json_test.go b/shell/point/json/json_test.go index 3bf2745eb..4e4c61e6d 100644 --- a/shell/point/json/json_test.go +++ b/shell/point/json/json_test.go @@ -4,6 +4,8 @@ import ( "path/filepath" "testing" + v2net "github.com/v2ray/v2ray-core/common/net" + netassert "github.com/v2ray/v2ray-core/common/net/testing/assert" _ "github.com/v2ray/v2ray-core/proxy/dokodemo/json" _ "github.com/v2ray/v2ray-core/proxy/freedom/json" _ "github.com/v2ray/v2ray-core/proxy/socks/json" @@ -23,7 +25,7 @@ func TestClientSampleConfig(t *testing.T) { pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json")) assert.Error(err).IsNil() - assert.Uint16(pointConfig.Port().Value()).Positive() + netassert.Port(pointConfig.Port()).IsValid() assert.Pointer(pointConfig.InboundConfig()).IsNotNil() assert.Pointer(pointConfig.OutboundConfig()).IsNotNil() @@ -68,7 +70,7 @@ func TestDetourConfig(t *testing.T) { detour := detours[0] assert.StringLiteral(detour.Protocol()).Equals("dokodemo-door") - assert.Uint16(detour.PortRange().From().Value()).Equals(uint16(28394)) - assert.Uint16(detour.PortRange().To().Value()).Equals(uint16(28394)) + netassert.Port(detour.PortRange().From()).Equals(v2net.Port(28394)) + netassert.Port(detour.PortRange().To()).Equals(v2net.Port(28394)) assert.Pointer(detour.Settings()).IsNotNil() }