-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet_test.go
More file actions
41 lines (32 loc) · 932 Bytes
/
net_test.go
File metadata and controls
41 lines (32 loc) · 932 Bytes
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
40
41
package crab
import (
"net"
"testing"
"github.com/serialt/crab/internal"
)
func TestLenToSubNetMask(t *testing.T) {
assert := internal.NewAssert(t, "TestLenToSubNetMask")
want8 := "255.0.0.0"
want32 := "255.255.255.255"
got32 := LenToSubNetMask(32)
assert.Equal(want32, got32)
got8 := LenToSubNetMask(8)
assert.Equal(want8, got8)
}
func TestIsPublicIPv4(t *testing.T) {
assert := internal.NewAssert(t, "TestIsPublicIPv4")
ip1 := net.ParseIP("8.8.8.8")
ip2 := net.ParseIP("119.29.29.29")
ip3 := net.ParseIP("10.10.10.5")
ip4 := net.ParseIP("127.0.0.1")
assert.Equal(true, IsPublicIPv4(ip1))
assert.Equal(true, IsPublicIPv4(ip2))
assert.Equal(false, IsPublicIPv4(ip3))
assert.Equal(false, IsPublicIPv4(ip4))
}
func TestGetMyIPLocation(t *testing.T) {
assert := internal.NewAssert(t, "TestGetMyIPLocation")
loc, err := GetMyIPLocation()
assert.IsNil(err)
t.Logf("Get ip Info, data: %v", Marshal(loc))
}