Location.t 2.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl Location.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use strict;
use warnings;

11
# Where to find the test database.
12
my $testdb = $ENV{'database'};
13
my $keyfile = $ENV{'keyfile'};
14

15
use Test::More tests => 10;
16 17 18 19 20 21
BEGIN { use_ok('Location') };

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
22 23 24 25 26

# Address which should be used for database lookup.
my $address = "2a07:1c44:5800::1";

# Connect to the database.
27 28 29
my $db = &Location::init("$testdb");

# Verify
30 31
my $status = &Location::verify($db, $keyfile);
ok($status, "This database is valid");
32 33 34 35 36 37 38 39 40 41 42 43

my $vendor = &Location::get_vendor($db);
ok($vendor eq "IPFire Project", "Test 1 - Get Database Vendor");

my $license = &Location::get_license($db);
ok($license eq "CC", "Test 2 - Get Database license");

my $description = &Location::get_description($db);
ok($description eq "This is a geo location database", "Test 3 - Get Database Description");

my $country_code = &Location::lookup_country_code($db, $address);
ok($country_code eq "DE", "Test 4 - Lookup country code for $address");
44 45 46 47 48 49

$country_code = &Location::lookup_country_code($db, "1.1.1.1");
if(defined($country_code)) { fail("Test 5 - Lookup country code for address not in Database."); }

$country_code = &Location::lookup_country_code($db, "a.b.c.d");
if(defined($country_code)) { fail("Test 6 - Lookup country code for invalid address.") }
50 51 52 53 54 55 56 57 58

my $as_number = &Location::lookup_asn($db, $address);
ok($as_number eq "204867", "Test 7 - Lookup Autonomous System Number for $address.");

$as_number = &Location::lookup_asn($db, "1.1.1.1");
if(defined($as_number)) { fail("Test 8 - Lookup Autonomous System Number for address not in Database.") }

$as_number = &Location::lookup_asn($db, "a.b.c.d");
if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") }
59

Stefan Schantl's avatar
Stefan Schantl committed
60 61 62
my $as_name = &Location::get_as_name($db, "204867");
ok($as_name eq "Lightning Wire Labs GmbH", "Test 10 - Get name for AS204867.");

63
my @locations = &Location::database_countries($db);
Stefan Schantl's avatar
Stefan Schantl committed
64
ok(@locations != 0, "Test 11 - Get database countries.");
65 66 67

my $network_flag_anycast = &Location::lookup_network_has_flag($db, $address, "LOC_NETWORK_FLAG_ANYCAST");
ok($network_flag_anycast, "Network has Anycast flag.");