destination.go 1.2 KB

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