@@ -22,16 +22,16 @@ import (
2222
2323// TestIPInfoAnnotator tests the IPInfoAnnotator with known IP addresses against a constant MMDB file in ./data-snapshots
2424// Unfortunately, I only have a free account for IPInfo, so can only test parsing for the Lite api with a real DB file.
25- func TestIPInfoAnnotator (t * testing.T ) {
25+ func TestIPInfoAnnotatorLite (t * testing.T ) {
2626 tests := []struct {
2727 testName string
2828 ipAddr net.IP
29- expectedResult * IPInfoOutput
29+ expectedResult * IPInfoModuleOutput
3030 }{
3131 {
3232 testName : "Positive Test Case, IPv4" ,
3333 ipAddr : net .ParseIP ("1.1.1.1" ),
34- expectedResult : & IPInfoOutput {
34+ expectedResult : & IPInfoModuleOutput {
3535 ASN : "AS13335" ,
3636 ASName : "Cloudflare, Inc." ,
3737 ASDomain : "cloudflare.com" ,
@@ -43,7 +43,7 @@ func TestIPInfoAnnotator(t *testing.T) {
4343 }, {
4444 testName : "Positive Test Case, IPv6" ,
4545 ipAddr : net .ParseIP ("2606:4700:4700::1111" ),
46- expectedResult : & IPInfoOutput {
46+ expectedResult : & IPInfoModuleOutput {
4747 ASN : "AS13335" ,
4848 ASName : "Cloudflare, Inc." ,
4949 ASDomain : "cloudflare.com" ,
@@ -86,3 +86,101 @@ func TestIPInfoAnnotator(t *testing.T) {
8686 })
8787 }
8888}
89+
90+ func TestIPInfoAnnotatorCore (t * testing.T ) {
91+ expectedResult := & IPInfoModuleOutput {
92+ City : "Brisbane" ,
93+ Region : "Queensland" ,
94+ RegionCode : "QLD" ,
95+ Country : "Australia" ,
96+ CountryCode : "AU" ,
97+ Continent : "Oceania" ,
98+ ContinentCode : "OC" ,
99+ Latitude : - 27.48159 ,
100+ Longitude : 153.0175 ,
101+ Timezone : "Australia/Brisbane" ,
102+ PostalCode : "4101" ,
103+ ASN : "AS13335" ,
104+ ASName : "Cloudflare, Inc." ,
105+ ASDomain : "cloudflare.com" ,
106+ ASType : "hosting" ,
107+ IsAnonymous : & []bool {true }[0 ],
108+ IsAnycast : & []bool {true }[0 ],
109+ IsHosting : & []bool {true }[0 ],
110+ IsMobile : & []bool {false }[0 ],
111+ IsSatellite : & []bool {false }[0 ],
112+ }
113+ inputIP := net .ParseIP ("1.0.0.1" )
114+ factory := & IPInfoAnnotatorFactory {
115+ DatabaseFilePath : "./data-snapshots/ipinfo_core_sample.mmdb" ,
116+ }
117+ err := factory .Initialize (nil )
118+ if err != nil {
119+ t .Fatalf ("Failed to initialize IPInfoAnnotatorFactory: %v" , err )
120+ }
121+ annotator := factory .MakeAnnotator (0 ).(* IPInfoAnnotator )
122+ err = annotator .Initialize ()
123+ if err != nil {
124+ t .Fatalf ("Failed to initialize IPInfoAnnotator: %v" , err )
125+ }
126+ result := annotator .Annotate (inputIP )
127+ if expectedResult == nil && result == nil {
128+ return // pass
129+ }
130+ if ! reflect .DeepEqual (result , expectedResult ) {
131+ t .Errorf ("Annotating IP %s gave = \n %v\n expected: \n %v" , inputIP , result , expectedResult )
132+ }
133+ }
134+
135+ func TestIPInfoAnnotatorPlus (t * testing.T ) {
136+ expectedResult := & IPInfoModuleOutput {
137+ City : "Brisbane" ,
138+ Region : "Queensland" ,
139+ RegionCode : "QLD" ,
140+ Country : "Australia" ,
141+ CountryCode : "AU" ,
142+ Continent : "Oceania" ,
143+ ContinentCode : "OC" ,
144+ Latitude : - 27.48159 ,
145+ Longitude : 153.0175 ,
146+ Timezone : "Australia/Brisbane" ,
147+ PostalCode : "4101" ,
148+ GeonameID : 2174003 ,
149+ Radius : 200 ,
150+ ASN : "AS13335" ,
151+ ASName : "Cloudflare, Inc." ,
152+ ASDomain : "cloudflare.com" ,
153+ ASType : "hosting" ,
154+ ASChanged : "2025-09-28" ,
155+ GeoChanged : "2024-02-18" ,
156+ IsAnonymous : & []bool {true }[0 ],
157+ IsAnycast : & []bool {true }[0 ],
158+ IsHosting : & []bool {true }[0 ],
159+ IsMobile : & []bool {false }[0 ],
160+ IsSatellite : & []bool {false }[0 ],
161+ IsProxy : & []bool {false }[0 ],
162+ IsRelay : & []bool {false }[0 ],
163+ IsTOR : & []bool {false }[0 ],
164+ IsVPN : & []bool {true }[0 ],
165+ }
166+ inputIP := net .ParseIP ("1.0.0.1" )
167+ factory := & IPInfoAnnotatorFactory {
168+ DatabaseFilePath : "./data-snapshots/ipinfo_plus_sample.mmdb" ,
169+ }
170+ err := factory .Initialize (nil )
171+ if err != nil {
172+ t .Fatalf ("Failed to initialize IPInfoAnnotatorFactory: %v" , err )
173+ }
174+ annotator := factory .MakeAnnotator (0 ).(* IPInfoAnnotator )
175+ err = annotator .Initialize ()
176+ if err != nil {
177+ t .Fatalf ("Failed to initialize IPInfoAnnotator: %v" , err )
178+ }
179+ result := annotator .Annotate (inputIP )
180+ if expectedResult == nil && result == nil {
181+ return // pass
182+ }
183+ if ! reflect .DeepEqual (result , expectedResult ) {
184+ t .Errorf ("Annotating IP %s gave = \n %v\n expected: \n %v" , inputIP , result , expectedResult )
185+ }
186+ }
0 commit comments