destination.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package assert
  2. import (
  3. v2net "v2ray.com/core/common/net"
  4. )
  5. func (this *Assert) Destination(value v2net.Destination) *DestinationSubject {
  6. return &DestinationSubject{
  7. Subject: Subject{
  8. disp: value.String(),
  9. a: this,
  10. },
  11. value: value,
  12. }
  13. }
  14. type DestinationSubject struct {
  15. Subject
  16. value v2net.Destination
  17. }
  18. func (this *DestinationSubject) IsTCP() {
  19. if this.value.Network() != v2net.TCPNetwork {
  20. this.Fail("is", "a TCP destination")
  21. }
  22. }
  23. func (this *DestinationSubject) IsNotTCP() {
  24. if this.value.Network() == v2net.TCPNetwork {
  25. this.Fail("is not", "a TCP destination")
  26. }
  27. }
  28. func (this *DestinationSubject) IsUDP() {
  29. if this.value.Network() != v2net.UDPNetwork {
  30. this.Fail("is", "a UDP destination")
  31. }
  32. }
  33. func (this *DestinationSubject) IsNotUDP() {
  34. if this.value.Network() == v2net.UDPNetwork {
  35. this.Fail("is not", "a UDP destination")
  36. }
  37. }
  38. func (this *DestinationSubject) EqualsString(another string) {
  39. if this.value.String() != another {
  40. this.Fail("not equals to string", another)
  41. }
  42. }
  43. func (this *DestinationSubject) HasAddress() *AddressSubject {
  44. return this.a.Address(this.value.Address())
  45. }
  46. func (this *DestinationSubject) HasPort() *PortSubject {
  47. return this.a.Port(this.value.Port())
  48. }