@@ -32,19 +32,20 @@ fn expectEqualMaps(
32
32
}
33
33
}
34
34
35
+ const allocator = std .testing .allocator ;
35
36
const expectEqual = std .testing .expectEqual ;
36
37
const expectEqualStrings = std .testing .expectEqualStrings ;
37
38
const expectEqualDeep = std .testing .expectEqualDeep ;
38
39
39
40
test "GeoLite2 Country" {
40
- var db = try Reader .open_mmap (
41
- std . testing . allocator ,
41
+ var db = try Reader .mmap (
42
+ allocator ,
42
43
"test-data/test-data/GeoLite2-Country-Test.mmdb" ,
43
44
);
44
- defer db .close ();
45
+ defer db .unmap ();
45
46
46
47
const ip = try std .net .Address .parseIp ("89.160.20.128" , 0 );
47
- const got = try db .lookup (geolite2 .Country , & ip );
48
+ const got = try db .lookup (allocator , geolite2 .Country , & ip );
48
49
defer got .deinit ();
49
50
50
51
try expectEqualStrings ("EU" , got .continent .code );
@@ -77,14 +78,14 @@ test "GeoLite2 Country" {
77
78
}
78
79
79
80
test "GeoLite2 City" {
80
- var db = try Reader .open_mmap (
81
- std . testing . allocator ,
81
+ var db = try Reader .mmap (
82
+ allocator ,
82
83
"test-data/test-data/GeoLite2-City-Test.mmdb" ,
83
84
);
84
- defer db .close ();
85
+ defer db .unmap ();
85
86
86
87
const ip = try std .net .Address .parseIp ("89.160.20.128" , 0 );
87
- const got = try db .lookup (geolite2 .City , & ip );
88
+ const got = try db .lookup (allocator , geolite2 .City , & ip );
88
89
defer got .deinit ();
89
90
90
91
try expectEqual (2694762 , got .city .geoname_id );
@@ -146,14 +147,14 @@ test "GeoLite2 City" {
146
147
}
147
148
148
149
test "GeoLite2 ASN" {
149
- var db = try Reader .open_mmap (
150
- std . testing . allocator ,
150
+ var db = try Reader .mmap (
151
+ allocator ,
151
152
"test-data/test-data/GeoLite2-ASN-Test.mmdb" ,
152
153
);
153
- defer db .close ();
154
+ defer db .unmap ();
154
155
155
156
const ip = try std .net .Address .parseIp ("89.160.20.128" , 0 );
156
- const got = try db .lookup (geolite2 .ASN , & ip );
157
+ const got = try db .lookup (allocator , geolite2 .ASN , & ip );
157
158
158
159
const want = geolite2.ASN {
159
160
.autonomous_system_number = 29518 ,
@@ -163,14 +164,14 @@ test "GeoLite2 ASN" {
163
164
}
164
165
165
166
test "GeoIP2 Country" {
166
- var db = try Reader .open_mmap (
167
- std . testing . allocator ,
167
+ var db = try Reader .mmap (
168
+ allocator ,
168
169
"test-data/test-data/GeoIP2-Country-Test.mmdb" ,
169
170
);
170
- defer db .close ();
171
+ defer db .unmap ();
171
172
172
173
const ip = try std .net .Address .parseIp ("89.160.20.128" , 0 );
173
- const got = try db .lookup (geoip2 .Country , & ip );
174
+ const got = try db .lookup (allocator , geoip2 .Country , & ip );
174
175
defer got .deinit ();
175
176
176
177
try expectEqualStrings ("EU" , got .continent .code );
@@ -210,14 +211,14 @@ test "GeoIP2 Country" {
210
211
}
211
212
212
213
test "GeoIP2 City" {
213
- var db = try Reader .open_mmap (
214
- std . testing . allocator ,
214
+ var db = try Reader .mmap (
215
+ allocator ,
215
216
"test-data/test-data/GeoIP2-City-Test.mmdb" ,
216
217
);
217
- defer db .close ();
218
+ defer db .unmap ();
218
219
219
220
const ip = try std .net .Address .parseIp ("89.160.20.128" , 0 );
220
- const got = try db .lookup (geoip2 .City , & ip );
221
+ const got = try db .lookup (allocator , geoip2 .City , & ip );
221
222
defer got .deinit ();
222
223
223
224
try expectEqual (2694762 , got .city .geoname_id );
@@ -286,14 +287,14 @@ test "GeoIP2 City" {
286
287
}
287
288
288
289
test "GeoIP2 Enterprise" {
289
- var db = try Reader .open_mmap (
290
- std . testing . allocator ,
290
+ var db = try Reader .mmap (
291
+ allocator ,
291
292
"test-data/test-data/GeoIP2-Enterprise-Test.mmdb" ,
292
293
);
293
- defer db .close ();
294
+ defer db .unmap ();
294
295
295
296
const ip = try std .net .Address .parseIp ("74.209.24.0" , 0 );
296
- const got = try db .lookup (geoip2 .Enterprise , & ip );
297
+ const got = try db .lookup (allocator , geoip2 .Enterprise , & ip );
297
298
defer got .deinit ();
298
299
299
300
try expectEqual (11 , got .city .confidence );
@@ -380,14 +381,14 @@ test "GeoIP2 Enterprise" {
380
381
}
381
382
382
383
test "GeoIP2 ISP" {
383
- var db = try Reader .open_mmap (
384
- std . testing . allocator ,
384
+ var db = try Reader .mmap (
385
+ allocator ,
385
386
"test-data/test-data/GeoIP2-ISP-Test.mmdb" ,
386
387
);
387
- defer db .close ();
388
+ defer db .unmap ();
388
389
389
390
const ip = try std .net .Address .parseIp ("89.160.20.112" , 0 );
390
- const got = try db .lookup (geoip2 .ISP , & ip );
391
+ const got = try db .lookup (allocator , geoip2 .ISP , & ip );
391
392
392
393
const want = geoip2.ISP {
393
394
.autonomous_system_number = 29518 ,
@@ -399,14 +400,14 @@ test "GeoIP2 ISP" {
399
400
}
400
401
401
402
test "GeoIP2 Connection-Type" {
402
- var db = try Reader .open_mmap (
403
- std . testing . allocator ,
403
+ var db = try Reader .mmap (
404
+ allocator ,
404
405
"test-data/test-data/GeoIP2-Connection-Type-Test.mmdb" ,
405
406
);
406
- defer db .close ();
407
+ defer db .unmap ();
407
408
408
409
const ip = try std .net .Address .parseIp ("96.1.20.112" , 0 );
409
- const got = try db .lookup (geoip2 .ConnectionType , & ip );
410
+ const got = try db .lookup (allocator , geoip2 .ConnectionType , & ip );
410
411
411
412
const want = geoip2.ConnectionType {
412
413
.connection_type = "Cable/DSL" ,
@@ -415,14 +416,14 @@ test "GeoIP2 Connection-Type" {
415
416
}
416
417
417
418
test "GeoIP2 Anonymous-IP" {
418
- var db = try Reader .open_mmap (
419
- std . testing . allocator ,
419
+ var db = try Reader .mmap (
420
+ allocator ,
420
421
"test-data/test-data/GeoIP2-Anonymous-IP-Test.mmdb" ,
421
422
);
422
- defer db .close ();
423
+ defer db .unmap ();
423
424
424
425
const ip = try std .net .Address .parseIp ("81.2.69.0" , 0 );
425
- const got = try db .lookup (geoip2 .AnonymousIP , & ip );
426
+ const got = try db .lookup (allocator , geoip2 .AnonymousIP , & ip );
426
427
427
428
const want = geoip2.AnonymousIP {
428
429
.is_anonymous = true ,
@@ -436,14 +437,14 @@ test "GeoIP2 Anonymous-IP" {
436
437
}
437
438
438
439
test "GeoIP2 DensityIncome" {
439
- var db = try Reader .open_mmap (
440
- std . testing . allocator ,
440
+ var db = try Reader .mmap (
441
+ allocator ,
441
442
"test-data/test-data/GeoIP2-DensityIncome-Test.mmdb" ,
442
443
);
443
- defer db .close ();
444
+ defer db .unmap ();
444
445
445
446
const ip = try std .net .Address .parseIp ("5.83.124.123" , 0 );
446
- const got = try db .lookup (geoip2 .DensityIncome , & ip );
447
+ const got = try db .lookup (allocator , geoip2 .DensityIncome , & ip );
447
448
448
449
const want = geoip2.DensityIncome {
449
450
.average_income = 32323 ,
@@ -453,14 +454,14 @@ test "GeoIP2 DensityIncome" {
453
454
}
454
455
455
456
test "GeoIP2 Domain" {
456
- var db = try Reader .open_mmap (
457
- std . testing . allocator ,
457
+ var db = try Reader .mmap (
458
+ allocator ,
458
459
"test-data/test-data/GeoIP2-Domain-Test.mmdb" ,
459
460
);
460
- defer db .close ();
461
+ defer db .unmap ();
461
462
462
463
const ip = try std .net .Address .parseIp ("66.92.80.123" , 0 );
463
- const got = try db .lookup (geoip2 .Domain , & ip );
464
+ const got = try db .lookup (allocator , geoip2 .Domain , & ip );
464
465
465
466
const want = geoip2.Domain {
466
467
.domain = "speakeasy.net" ,
0 commit comments