v2ray-core/testing/assert/port.go

45 lines
893 B
Go
Raw Normal View History

2015-12-02 16:27:55 +00:00
package assert
import (
2017-01-13 23:27:45 +00:00
"v2ray.com/core/common/net"
)
2017-01-13 23:27:45 +00:00
func (v *Assert) Port(value net.Port) *PortSubject {
2016-05-24 19:55:46 +00:00
return &PortSubject{
Subject: Subject{
2016-11-27 20:39:09 +00:00
a: v,
2016-05-24 19:55:46 +00:00
disp: value.String(),
},
value: value,
}
}
type PortSubject struct {
2016-05-24 13:29:08 +00:00
Subject
2017-01-13 23:27:45 +00:00
value net.Port
}
2017-01-13 23:27:45 +00:00
func (subject *PortSubject) Equals(expectation net.Port) {
if subject.value.Value() != expectation.Value() {
2016-05-24 19:55:46 +00:00
subject.Fail("is equal to", expectation.String())
}
}
2017-01-13 23:27:45 +00:00
func (subject *PortSubject) GreaterThan(expectation net.Port) {
if subject.value.Value() <= expectation.Value() {
2016-05-24 19:55:46 +00:00
subject.Fail("is greater than", expectation.String())
}
}
2017-01-13 23:27:45 +00:00
func (subject *PortSubject) LessThan(expectation net.Port) {
if subject.value.Value() >= expectation.Value() {
2016-05-24 19:55:46 +00:00
subject.Fail("is less than", expectation.String())
}
}
2015-12-02 20:44:01 +00:00
func (subject *PortSubject) IsValid() {
2015-12-02 20:58:46 +00:00
if subject.value == 0 {
2016-05-24 19:55:46 +00:00
subject.Fail("is", "a valid port")
2015-12-02 20:58:46 +00:00
}
2015-12-02 20:44:01 +00:00
}