]>
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 | |
18806c97 | 15 | use Test::More tests => 6; |
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. | |
2061ff77 | 27 | my $db = &Location::init("$testdb", "$keyfile"); |
85aa96e3 SS |
28 | |
29 | my $vendor = &Location::get_vendor($db); | |
30 | ok($vendor eq "IPFire Project", "Test 1 - Get Database Vendor"); | |
31 | ||
32 | my $license = &Location::get_license($db); | |
33 | ok($license eq "CC", "Test 2 - Get Database license"); | |
34 | ||
35 | my $description = &Location::get_description($db); | |
36 | ok($description eq "This is a geo location database", "Test 3 - Get Database Description"); | |
37 | ||
38 | my $country_code = &Location::lookup_country_code($db, $address); | |
39 | ok($country_code eq "DE", "Test 4 - Lookup country code for $address"); | |
946f4330 SS |
40 | |
41 | $country_code = &Location::lookup_country_code($db, "1.1.1.1"); | |
42 | if(defined($country_code)) { fail("Test 5 - Lookup country code for address not in Database."); } | |
43 | ||
44 | $country_code = &Location::lookup_country_code($db, "a.b.c.d"); | |
45 | if(defined($country_code)) { fail("Test 6 - Lookup country code for invalid address.") } | |
18806c97 SS |
46 | |
47 | my $as_number = &Location::lookup_asn($db, $address); | |
48 | ok($as_number eq "204867", "Test 7 - Lookup Autonomous System Number for $address."); | |
49 | ||
50 | $as_number = &Location::lookup_asn($db, "1.1.1.1"); | |
51 | if(defined($as_number)) { fail("Test 8 - Lookup Autonomous System Number for address not in Database.") } | |
52 | ||
53 | $as_number = &Location::lookup_asn($db, "a.b.c.d"); | |
54 | if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") } |