mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-29 05:25:21 -05:00
refactor common/net.Port
This commit is contained in:
@@ -11,7 +11,7 @@ func Address(value v2net.Address) *AddressSubject {
|
||||
}
|
||||
|
||||
type AddressSubject struct {
|
||||
*assert.Subject
|
||||
assert.Subject
|
||||
value v2net.Address
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ func Destination(value v2net.Destination) *DestinationSubject {
|
||||
}
|
||||
|
||||
type DestinationSubject struct {
|
||||
*assert.Subject
|
||||
assert.Subject
|
||||
value v2net.Destination
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package assert
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
@@ -10,7 +11,7 @@ func Port(value v2net.Port) *PortSubject {
|
||||
}
|
||||
|
||||
type PortSubject struct {
|
||||
*assert.Subject
|
||||
assert.Subject
|
||||
value v2net.Port
|
||||
}
|
||||
|
||||
@@ -40,3 +41,9 @@ func (subject *PortSubject) LessThan(expectation v2net.Port) {
|
||||
subject.Fail(subject.DisplayString(), "is less than", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PortSubject) IsValid() {
|
||||
if subject.value == 0 {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("a valid port"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package testing
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
var (
|
||||
port = int32(30000)
|
||||
)
|
||||
|
||||
func PickPort() uint16 {
|
||||
return uint16(atomic.AddInt32(&port, 1))
|
||||
func PickPort() v2net.Port {
|
||||
return v2net.Port(uint16(atomic.AddInt32(&port, 1)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user