Permalink
Browse files

Added regression tests.

  • Loading branch information...
1 parent 0ea0212 commit 0bb89cfb1c8d9c04082f04012f1ddba54ea85632 @tvondra committed Apr 3, 2012
Showing with 136 additions and 0 deletions.
  1. +4 −0 Makefile
  2. +83 −0 test/expected/base.out
  3. +49 −0 test/sql/base.sql
View
@@ -4,5 +4,9 @@ DATA = $(wildcard sql/*.sql)
PG_CONFIG = pg_config
PG91 = $(shell $(PG_CONFIG) --version | grep -qE " 8\.| 9\.0" && echo no || echo yes)
+TESTS = $(wildcard test/sql/*.sql)
+REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
+REGRESS_OPTS = --inputdir=test --load-language=plpgsql
+
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
View
@@ -0,0 +1,83 @@
+BEGIN;
+CREATE EXTENSION geoip;
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.31.24.0', '78.31.31.255', 'AA', 'Country A');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.41.8.0', '78.41.23.255', 'BB', 'Country B');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.44.0.0', '78.45.255.255', 'CC', 'Country C');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.80.0.0', '78.80.255.255', 'DD', 'Country D');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.102.0.0', '78.103.255.255', 'EE', 'Country E');
+-- country CC
+SELECT geoip_country_code('78.45.133.255'::inet);
+ geoip_country_code
+--------------------
+ CC
+(1 row)
+
+SELECT * FROM geoip_country('78.45.133.255'::inet);
+ begin_ip | end_ip | country | name
+-----------+---------------+---------+-----------
+ 78.44.0.0 | 78.45.255.255 | CC | Country C
+(1 row)
+
+-- no matching country record
+SELECT geoip_country_code('10.45.133.255'::inet);
+ geoip_country_code
+--------------------
+
+(1 row)
+
+SELECT * FROM geoip_country_code('10.45.133.255'::inet);
+ geoip_country_code
+--------------------
+
+(1 row)
+
+INSERT INTO geoip_city_location(loc_id, country, region, city, postal_code, latitude, longitude, metro_code, area_code) VALUES (21235, 'CZ', 52, 'A', NULL, 50.0833, 14.4667, NULL, NULL);
+INSERT INTO geoip_city_location(loc_id, country, region, city, postal_code, latitude, longitude, metro_code, area_code) VALUES (37990, 'CZ', 78, 'B', NULL, 49.2, 16.6333, NULL, NULL);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('31.7.243.0', '31.7.243.31', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('31.30.3.72', '31.30.3.79', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('46.13.32.0', '46.13.63.255', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('46.13.240.0', '46.13.255.255', 37990);
+-- city A
+SELECT geoip_city_location('31.7.243.10'::inet);
+ geoip_city_location
+---------------------
+ 21235
+(1 row)
+
+SELECT * FROM geoip_city('31.7.243.10'::inet);
+ loc_id | country | region | city | postal_code | latitude | longitude | metro_code | area_code
+--------+---------+--------+------+-------------+----------+-----------+------------+-----------
+ 21235 | CZ | 52 | A | | 50.0833 | 14.4667 | |
+(1 row)
+
+-- no matching city record
+SELECT geoip_city_location('10.7.243.10'::inet);
+ geoip_city_location
+---------------------
+
+(1 row)
+
+SELECT * FROM geoip_city('10.7.243.10'::inet);
+ loc_id | country | region | city | postal_code | latitude | longitude | metro_code | area_code
+--------+---------+--------+------+-------------+----------+-----------+------------+-----------
+ | | | | | | | |
+(1 row)
+
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.64.0', '1.11.95.255', 'AS38091 CJ-CABLENET');
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.96.0', '1.11.127.255', 'AS38669 ChungNam Broadcastin Co.');
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.128.0', '1.11.255.255', 'AS17839 DreamcityMedia');
+-- ASN CABLENET
+SELECT * FROM geoip_asn('1.11.66.10'::inet);
+ begin_ip | end_ip | name
+-----------+-------------+---------------------
+ 1.11.64.0 | 1.11.95.255 | AS38091 CJ-CABLENET
+(1 row)
+
+-- missing ASN records
+SELECT * FROM geoip_asn('10.11.66.10'::inet);
+ begin_ip | end_ip | name
+------------+--------------+------------------------
+ 1.11.128.0 | 1.11.255.255 | AS17839 DreamcityMedia
+(1 row)
+
+ROLLBACK;
View
@@ -0,0 +1,49 @@
+BEGIN;
+
+CREATE EXTENSION geoip;
+
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.31.24.0', '78.31.31.255', 'AA', 'Country A');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.41.8.0', '78.41.23.255', 'BB', 'Country B');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.44.0.0', '78.45.255.255', 'CC', 'Country C');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.80.0.0', '78.80.255.255', 'DD', 'Country D');
+INSERT INTO geoip_country(begin_ip, end_ip, country, name) VALUES ('78.102.0.0', '78.103.255.255', 'EE', 'Country E');
+
+-- country CC
+SELECT geoip_country_code('78.45.133.255'::inet);
+
+SELECT * FROM geoip_country('78.45.133.255'::inet);
+
+-- no matching country record
+SELECT geoip_country_code('10.45.133.255'::inet);
+
+SELECT * FROM geoip_country_code('10.45.133.255'::inet);
+
+INSERT INTO geoip_city_location(loc_id, country, region, city, postal_code, latitude, longitude, metro_code, area_code) VALUES (21235, 'CZ', 52, 'A', NULL, 50.0833, 14.4667, NULL, NULL);
+INSERT INTO geoip_city_location(loc_id, country, region, city, postal_code, latitude, longitude, metro_code, area_code) VALUES (37990, 'CZ', 78, 'B', NULL, 49.2, 16.6333, NULL, NULL);
+
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('31.7.243.0', '31.7.243.31', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('31.30.3.72', '31.30.3.79', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('46.13.32.0', '46.13.63.255', 21235);
+INSERT INTO geoip_city_block(begin_ip, end_ip, loc_id) VALUES ('46.13.240.0', '46.13.255.255', 37990);
+
+-- city A
+SELECT geoip_city_location('31.7.243.10'::inet);
+
+SELECT * FROM geoip_city('31.7.243.10'::inet);
+
+-- no matching city record
+SELECT geoip_city_location('10.7.243.10'::inet);
+
+SELECT * FROM geoip_city('10.7.243.10'::inet);
+
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.64.0', '1.11.95.255', 'AS38091 CJ-CABLENET');
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.96.0', '1.11.127.255', 'AS38669 ChungNam Broadcastin Co.');
+INSERT INTO geoip_asn(begin_ip, end_ip, name) VALUES ('1.11.128.0', '1.11.255.255', 'AS17839 DreamcityMedia');
+
+-- ASN CABLENET
+SELECT * FROM geoip_asn('1.11.66.10'::inet);
+
+-- missing ASN records
+SELECT * FROM geoip_asn('10.11.66.10'::inet);
+
+ROLLBACK;

0 comments on commit 0bb89cf

Please sign in to comment.