destination.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package assert
  2. import (
  3. v2net "github.com/v2ray/v2ray-core/common/net"
  4. "github.com/v2ray/v2ray-core/common/serial"
  5. )
  6. func Destination(value v2net.Destination) *DestinationSubject {
  7. return &DestinationSubject{value: value}
  8. }
  9. type DestinationSubject struct {
  10. Subject
  11. value v2net.Destination
  12. }
  13. func (this *DestinationSubject) Named(name string) *DestinationSubject {
  14. this.Subject.Named(name)
  15. return this
  16. }
  17. func (this *DestinationSubject) DisplayString() string {
  18. return this.Subject.DisplayString(this.value.String())
  19. }
  20. func (this *DestinationSubject) IsTCP() {
  21. if !this.value.IsTCP() {
  22. this.Fail(this.DisplayString(), "is", serial.StringT("a TCP destination"))
  23. }
  24. }
  25. func (this *DestinationSubject) IsNotTCP() {
  26. if this.value.IsTCP() {
  27. this.Fail(this.DisplayString(), "is not", serial.StringT("a TCP destination"))
  28. }
  29. }
  30. func (this *DestinationSubject) IsUDP() {
  31. if !this.value.IsUDP() {
  32. this.Fail(this.DisplayString(), "is", serial.StringT("a UDP destination"))
  33. }
  34. }
  35. func (this *DestinationSubject) IsNotUDP() {
  36. if this.value.IsUDP() {
  37. this.Fail(this.DisplayString(), "is not", serial.StringT("a UDP destination"))
  38. }
  39. }