mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-09 11:51:02 -05:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
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"
|
|
)
|
|
|
|
func Port(value v2net.Port) *PortSubject {
|
|
return &PortSubject{value: value}
|
|
}
|
|
|
|
type PortSubject struct {
|
|
assert.Subject
|
|
value v2net.Port
|
|
}
|
|
|
|
func (subject *PortSubject) Named(name string) *PortSubject {
|
|
subject.Subject.Named(name)
|
|
return subject
|
|
}
|
|
|
|
func (subject *PortSubject) DisplayString() string {
|
|
return subject.Subject.DisplayString(subject.value.String())
|
|
}
|
|
|
|
func (subject *PortSubject) Equals(expectation v2net.Port) {
|
|
if subject.value.Value() != expectation.Value() {
|
|
subject.Fail(subject.DisplayString(), "is equal to", expectation)
|
|
}
|
|
}
|
|
|
|
func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
|
|
if subject.value.Value() <= expectation.Value() {
|
|
subject.Fail(subject.DisplayString(), "is greater than", expectation)
|
|
}
|
|
}
|
|
|
|
func (subject *PortSubject) LessThan(expectation v2net.Port) {
|
|
if subject.value.Value() >= expectation.Value() {
|
|
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"))
|
|
}
|
|
}
|