]>
Commit | Line | Data |
---|---|---|
1ea740e9 SS |
1 | # Before 'make install' is performed this script should be runnable with |
2 | # 'make test'. After 'make install' it should work as 'perl Location.t' | |
3 | ||
4 | ######################### | |
5 | ||
6 | # change 'tests => 1' to 'tests => last_test_to_print'; | |
7 | ||
8 | use strict; | |
9 | use warnings; | |
10 | ||
85aa96e3 | 11 | # Where to find the test database. |
f852b157 | 12 | my $testdb = $ENV{'database'}; |
2061ff77 | 13 | my $keyfile = $ENV{'keyfile'}; |
85aa96e3 | 14 | |
30c8e528 | 15 | use Test::More tests => 9; |
1ea740e9 SS |
16 | BEGIN { use_ok('Location') }; |
17 | ||
18 | ######################### | |
19 | ||
20 | # Insert your test code below, the Test::More module is use()ed here so read | |
21 | # its man page ( perldoc Test::More ) for help writing this test script. | |
85aa96e3 SS |
22 | |
23 | # Address which should be used for database lookup. | |
24 | my $address = "2a07:1c44:5800::1"; | |
25 | ||
26 | # Connect to the database. | |
3bbf013a MT |
27 | my $db = &Location::init("$testdb"); |
28 | ||
29 | # Verify | |
70735dc3 MT |
30 | my $status = &Location::verify($db, $keyfile); |
31 | ok($status, "This database is valid"); | |
85aa96e3 SS |
32 | |
33 | my $vendor = &Location::get_vendor($db); | |
34 | ok($vendor eq "IPFire Project", "Test 1 - Get Database Vendor"); | |
35 | ||
36 | my $license = &Location::get_license($db); | |
37 | ok($license eq "CC", "Test 2 - Get Database license"); | |
38 | ||
39 | my $description = &Location::get_description($db); | |
40 | ok($description eq "This is a geo location database", "Test 3 - Get Database Description"); | |
41 | ||
42 | my $country_code = &Location::lookup_country_code($db, $address); | |
43 | ok($country_code eq "DE", "Test 4 - Lookup country code for $address"); | |
946f4330 SS |
44 | |
45 | $country_code = &Location::lookup_country_code($db, "1.1.1.1"); | |
46 | if(defined($country_code)) { fail("Test 5 - Lookup country code for address not in Database."); } | |
47 | ||
48 | $country_code = &Location::lookup_country_code($db, "a.b.c.d"); | |
49 | if(defined($country_code)) { fail("Test 6 - Lookup country code for invalid address.") } | |
18806c97 SS |
50 | |
51 | my $as_number = &Location::lookup_asn($db, $address); | |
52 | ok($as_number eq "204867", "Test 7 - Lookup Autonomous System Number for $address."); | |
53 | ||
54 | $as_number = &Location::lookup_asn($db, "1.1.1.1"); | |
55 | if(defined($as_number)) { fail("Test 8 - Lookup Autonomous System Number for address not in Database.") } | |
56 | ||
57 | $as_number = &Location::lookup_asn($db, "a.b.c.d"); | |
58 | if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") } | |
084b5bf4 | 59 | |
30c8e528 SS |
60 | my $as_name = &Location::get_as_name($db, "204867"); |
61 | ok($as_name eq "Lightning Wire Labs GmbH", "Test 10 - Get name for AS204867."); | |
62 | ||
084b5bf4 | 63 | my @locations = &Location::database_countries($db); |
30c8e528 | 64 | ok(@locations != 0, "Test 11 - Get database countries."); |