ip.go 792 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package assert
  2. import (
  3. "bytes"
  4. "net"
  5. "github.com/v2ray/v2ray-core/common/serial"
  6. "github.com/v2ray/v2ray-core/testing/assert"
  7. )
  8. func IP(value net.IP) *IPSubject {
  9. return &IPSubject{value: value}
  10. }
  11. type IPSubject struct {
  12. assert.Subject
  13. value net.IP
  14. }
  15. func (subject *IPSubject) Named(name string) *IPSubject {
  16. subject.Subject.Named(name)
  17. return subject
  18. }
  19. func (subject *IPSubject) DisplayString() string {
  20. return subject.Subject.DisplayString(subject.value.String())
  21. }
  22. func (subject *IPSubject) IsNil() {
  23. if subject.value != nil {
  24. subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("nil"))
  25. }
  26. }
  27. func (subject *IPSubject) Equals(ip net.IP) {
  28. if !bytes.Equal([]byte(subject.value), []byte(ip)) {
  29. subject.Fail(subject.DisplayString(), "equals to", ip)
  30. }
  31. }