1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-05 19:44:32 -04:00
v2fly/testing/assert/ip.go
2016-05-24 15:29:08 +02:00

39 lines
733 B
Go

package assert
import (
"bytes"
"net"
"github.com/v2ray/v2ray-core/common/serial"
)
func IP(value net.IP) *IPSubject {
return &IPSubject{value: value}
}
type IPSubject struct {
Subject
value net.IP
}
func (subject *IPSubject) Named(name string) *IPSubject {
subject.Subject.Named(name)
return subject
}
func (subject *IPSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *IPSubject) IsNil() {
if subject.value != nil {
subject.Fail(subject.DisplayString(), "is", serial.StringT("nil"))
}
}
func (subject *IPSubject) Equals(ip net.IP) {
if !bytes.Equal([]byte(subject.value), []byte(ip)) {
subject.Fail(subject.DisplayString(), "equals to", ip)
}
}