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
|
|
|
}
|
|
|
|
}
|