port.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 Port(value v2net.Port) *PortSubject {
  8. return &PortSubject{value: value}
  9. }
  10. type PortSubject struct {
  11. assert.Subject
  12. value v2net.Port
  13. }
  14. func (subject *PortSubject) Named(name string) *PortSubject {
  15. subject.Subject.Named(name)
  16. return subject
  17. }
  18. func (subject *PortSubject) DisplayString() string {
  19. return subject.Subject.DisplayString(subject.value.String())
  20. }
  21. func (subject *PortSubject) Equals(expectation v2net.Port) {
  22. if subject.value.Value() != expectation.Value() {
  23. subject.Fail(subject.DisplayString(), "is equal to", expectation)
  24. }
  25. }
  26. func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
  27. if subject.value.Value() <= expectation.Value() {
  28. subject.Fail(subject.DisplayString(), "is greater than", expectation)
  29. }
  30. }
  31. func (subject *PortSubject) LessThan(expectation v2net.Port) {
  32. if subject.value.Value() >= expectation.Value() {
  33. subject.Fail(subject.DisplayString(), "is less than", expectation)
  34. }
  35. }
  36. func (subject *PortSubject) IsValid() {
  37. if subject.value == 0 {
  38. subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("a valid port"))
  39. }
  40. }