Explorar el Código

simplify test

v2ray hace 10 años
padre
commit
c54c0218e0
Se han modificado 3 ficheros con 12 adiciones y 10 borrados
  1. 6 6
      common/net/json/portrange.go
  2. 1 1
      common/net/testing/port.go
  3. 5 3
      shell/point/json/json_test.go

+ 6 - 6
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)

+ 1 - 1
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))
 }

+ 5 - 3
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()
 }