]> git.ipfire.org Git - location/libloc.git/blame - src/perl/t/Location.t
perl: Add get_as_name()
[location/libloc.git] / src / perl / t / Location.t
CommitLineData
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
8use strict;
9use warnings;
10
85aa96e3 11# Where to find the test database.
f852b157 12my $testdb = $ENV{'database'};
2061ff77 13my $keyfile = $ENV{'keyfile'};
85aa96e3 14
30c8e528 15use Test::More tests => 9;
1ea740e9
SS
16BEGIN { 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.
24my $address = "2a07:1c44:5800::1";
25
26# Connect to the database.
3bbf013a
MT
27my $db = &Location::init("$testdb");
28
29# Verify
70735dc3
MT
30my $status = &Location::verify($db, $keyfile);
31ok($status, "This database is valid");
85aa96e3
SS
32
33my $vendor = &Location::get_vendor($db);
34ok($vendor eq "IPFire Project", "Test 1 - Get Database Vendor");
35
36my $license = &Location::get_license($db);
37ok($license eq "CC", "Test 2 - Get Database license");
38
39my $description = &Location::get_description($db);
40ok($description eq "This is a geo location database", "Test 3 - Get Database Description");
41
42my $country_code = &Location::lookup_country_code($db, $address);
43ok($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");
46if(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");
49if(defined($country_code)) { fail("Test 6 - Lookup country code for invalid address.") }
18806c97
SS
50
51my $as_number = &Location::lookup_asn($db, $address);
52ok($as_number eq "204867", "Test 7 - Lookup Autonomous System Number for $address.");
53
54$as_number = &Location::lookup_asn($db, "1.1.1.1");
55if(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");
58if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") }
084b5bf4 59
30c8e528
SS
60my $as_name = &Location::get_as_name($db, "204867");
61ok($as_name eq "Lightning Wire Labs GmbH", "Test 10 - Get name for AS204867.");
62
084b5bf4 63my @locations = &Location::database_countries($db);
30c8e528 64ok(@locations != 0, "Test 11 - Get database countries.");