2015-12-06 05:00:10 -05:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2016-05-24 15:55:46 -04:00
|
|
|
func (this *Assert) IP(value net.IP) *IPSubject {
|
|
|
|
return &IPSubject{
|
|
|
|
Subject: Subject{
|
|
|
|
a: this,
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|