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