forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ip.go
39 lines (31 loc) · 792 Bytes
/
ip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package assert
import (
"bytes"
"net"
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/testing/assert"
)
func IP(value net.IP) *IPSubject {
return &IPSubject{value: value}
}
type IPSubject struct {
assert.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.StringLiteral("nil"))
}
}
func (subject *IPSubject) Equals(ip net.IP) {
if !bytes.Equal([]byte(subject.value), []byte(ip)) {
subject.Fail(subject.DisplayString(), "equals to", ip)
}
}