-
Notifications
You must be signed in to change notification settings - Fork 9
/
types_test.go
123 lines (116 loc) · 2.87 KB
/
types_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2017 Tim Heckman
// Use of this source code is governed by the MIT License that can be found in
// the LICENSE file at the root of this repository.
package ipdata
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_IP_String(t *testing.T) {
ip := IP{IP: "8.8.8.8"}
if ip.String() != "8.8.8.8" {
t.Errorf("ip.String() = %q, want %q", ip.String(), "8.8.8.8")
}
}
func Test_bulkToIP(t *testing.T) {
bip := bulkIP{
IP: "76.14.47.42",
ASN: ASN{
ASN: "AS11404",
Name: "vanoppen.biz LLC",
Domain: "wavebroadband.com",
Route: "76.14.0.0/17",
Type: "isp",
},
Organization: "vanoppen.biz LLC",
City: "San Francisco",
Region: "California",
Postal: "94132",
CountryName: "United States",
CountryCode: "US",
Flag: tjFlagURL,
EmojiUnicode: `U+1F1FA U+1F1F8`,
ContinentName: "North America",
ContinentCode: "NA",
Latitude: 37.723,
Longitude: -122.4842,
CallingCode: "1",
IsEU: true,
Languages: []Language{{Name: "English (US)", Native: "en-us"}},
Currency: &Currency{
Name: "US Dollar",
Code: "USD",
Symbol: "$",
Native: "$",
Plural: "US dollars",
},
TimeZone: &TimeZone{
Name: "America/Los_Angeles",
Abbreviation: "PST",
Offset: "-0800",
IsDST: false,
CurrentTime: "2019-02-27T15:00:32.745936-08:00",
},
Threat: &Threat{
IsTOR: false,
IsProxy: false,
IsAnonymous: false,
IsKnownAttacker: false,
IsKnownAbuser: false,
IsThreat: true,
IsBogon: false,
},
}
ip := &IP{
IP: "76.14.47.42",
ASN: ASN{
ASN: "AS11404",
Name: "vanoppen.biz LLC",
Domain: "wavebroadband.com",
Route: "76.14.0.0/17",
Type: "isp",
},
Organization: "vanoppen.biz LLC",
City: "San Francisco",
Region: "California",
Postal: "94132",
CountryName: "United States",
CountryCode: "US",
Flag: tjFlagURL,
EmojiUnicode: `U+1F1FA U+1F1F8`,
ContinentName: "North America",
ContinentCode: "NA",
Latitude: 37.723,
Longitude: -122.4842,
CallingCode: "1",
IsEU: true,
Languages: []Language{{Name: "English (US)", Native: "en-us"}},
Currency: &Currency{
Name: "US Dollar",
Code: "USD",
Symbol: "$",
Native: "$",
Plural: "US dollars",
},
TimeZone: &TimeZone{
Name: "America/Los_Angeles",
Abbreviation: "PST",
Offset: "-0800",
IsDST: false,
CurrentTime: "2019-02-27T15:00:32.745936-08:00",
},
Threat: &Threat{
IsTOR: false,
IsProxy: false,
IsAnonymous: false,
IsKnownAttacker: false,
IsKnownAbuser: false,
IsThreat: true,
IsBogon: false,
},
}
got := bulkToIP(bip)
if diff := cmp.Diff(ip, got); diff != "" {
t.Fatalf("IP differs: (-want +got)\n%s", diff)
}
}