2015-12-02 11:27:55 -05:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
2017-01-13 18:27:45 -05:00
|
|
|
"v2ray.com/core/common/net"
|
2015-12-02 11:27:55 -05:00
|
|
|
)
|
|
|
|
|
2017-01-13 18:27:45 -05:00
|
|
|
func (v *Assert) Destination(value net.Destination) *DestinationSubject {
|
2016-05-24 15:55:46 -04:00
|
|
|
return &DestinationSubject{
|
|
|
|
Subject: Subject{
|
|
|
|
disp: value.String(),
|
2016-11-27 15:39:09 -05:00
|
|
|
a: v,
|
2016-05-24 15:55:46 -04:00
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type DestinationSubject struct {
|
2016-05-24 09:29:08 -04:00
|
|
|
Subject
|
2017-01-13 18:27:45 -05:00
|
|
|
value net.Destination
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) IsTCP() {
|
2017-01-13 18:27:45 -05:00
|
|
|
if v.value.Network != net.Network_TCP {
|
2016-11-27 15:39:09 -05:00
|
|
|
v.Fail("is", "a TCP destination")
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) IsNotTCP() {
|
2017-01-13 18:27:45 -05:00
|
|
|
if v.value.Network == net.Network_TCP {
|
2016-11-27 15:39:09 -05:00
|
|
|
v.Fail("is not", "a TCP destination")
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) IsUDP() {
|
2017-01-13 18:27:45 -05:00
|
|
|
if v.value.Network != net.Network_UDP {
|
2016-11-27 15:39:09 -05:00
|
|
|
v.Fail("is", "a UDP destination")
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) IsNotUDP() {
|
2017-01-13 18:27:45 -05:00
|
|
|
if v.value.Network == net.Network_UDP {
|
2016-11-27 15:39:09 -05:00
|
|
|
v.Fail("is not", "a UDP destination")
|
2016-05-24 15:55:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) EqualsString(another string) {
|
|
|
|
if v.value.String() != another {
|
|
|
|
v.Fail("not equals to string", another)
|
2015-12-02 11:27:55 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-24 15:55:46 -04:00
|
|
|
|
2017-04-02 03:48:30 -04:00
|
|
|
func (v *DestinationSubject) Equals(another net.Destination) {
|
|
|
|
if v.value != another {
|
|
|
|
v.Fail("not equals to", another.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) HasAddress() *AddressSubject {
|
|
|
|
return v.a.Address(v.value.Address)
|
2016-05-24 15:55:46 -04:00
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *DestinationSubject) HasPort() *PortSubject {
|
|
|
|
return v.a.Port(v.value.Port)
|
2016-05-24 15:55:46 -04:00
|
|
|
}
|