1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-20 12:14:15 -04:00
v2fly/testing/assert/ip.go

34 lines
488 B
Go
Raw Normal View History

2015-12-06 05:00:10 -05:00
package assert
import (
"bytes"
"net"
)
2016-11-27 15:39:09 -05:00
func (v *Assert) IP(value net.IP) *IPSubject {
2016-05-24 15:55:46 -04:00
return &IPSubject{
Subject: Subject{
2016-11-27 15:39:09 -05:00
a: v,
2016-05-24 15:55:46 -04:00
disp: value.String(),
},
value: value,
}
2015-12-06 05:00:10 -05:00
}
type IPSubject struct {
2016-05-24 09:29:08 -04:00
Subject
2015-12-06 05:00:10 -05:00
value net.IP
}
func (subject *IPSubject) IsNil() {
if subject.value != nil {
2016-05-24 15:55:46 -04:00
subject.Fail("is", "nil")
2015-12-06 05:00:10 -05:00
}
}
func (subject *IPSubject) Equals(ip net.IP) {
if !bytes.Equal([]byte(subject.value), []byte(ip)) {
2016-05-24 15:55:46 -04:00
subject.Fail("equals to", ip.String())
2015-12-06 05:00:10 -05:00
}
}