mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
simplify test
This commit is contained in:
parent
092217182a
commit
c54c0218e0
@ -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)
|
||||
|
@ -11,5 +11,5 @@ var (
|
||||
)
|
||||
|
||||
func PickPort() v2net.Port {
|
||||
return v2net.Port(uint16(atomic.AddInt32(&port, 1)))
|
||||
return v2net.Port(atomic.AddInt32(&port, 1))
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user