Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jloh committed Oct 17, 2018
1 parent 47c6ef9 commit 495843d
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions t/v1/01-utils.t
Expand Up @@ -253,7 +253,7 @@ GET /t
["OK","OK"]
=== TEST 12: Test geo_lookup
=== TEST 12: Test geoip_lookup
--- http_config eval
"$::HttpConfig"
--- config
Expand All @@ -262,12 +262,12 @@ GET /t
default_type text/plain;
charset utf-8;
content_by_lua_block {
local geo_lookup = require("geojs.utils").geoip_lookup
local geoip_lookup = require("geojs.utils").geoip_lookup
local args = ngx.req.get_uri_args()
local ip = args.ip
local cjson = require("cjson")
ngx.print(cjson.encode(geo_lookup(ip)))
ngx.print(cjson.encode(geoip_lookup(ip)))
}
}
--- request eval
Expand All @@ -277,3 +277,55 @@ GET /t
[error]
--- response_body eval
['{"subdivisions":[{"names":{}}],"autonomous_system_number":15169,"registered_country":{"geoname_id":6252001,"names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"continent":{"geoname_id":6255149,"names":{"en":"North America","ru":"Северная Америка","fr":"Amérique du Nord","pt-BR":"América do Norte","zh-CN":"北美洲","es":"Norteamérica","de":"Nordamerika","ja":"北アメリカ"},"code":"NA"},"postal":{},"city":{"names":{}},"country":{"geoname_id":6252001,"iso_code3":"USA","names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"location":{"latitude":37.751,"accuracy_radius":1000,"longitude":-97.822},"autonomous_system_organization":"Google LLC"}','{"subdivisions":[{"names":{}}],"autonomous_system_number":15169,"registered_country":{"geoname_id":6252001,"names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"continent":{"geoname_id":6255149,"names":{"en":"North America","ru":"Северная Америка","fr":"Amérique du Nord","pt-BR":"América do Norte","zh-CN":"北美洲","es":"Norteamérica","de":"Nordamerika","ja":"北アメリカ"},"code":"NA"},"postal":{},"city":{"names":{}},"country":{"geoname_id":6252001,"iso_code3":"USA","names":{"en":"United States","ru":"США","fr":"États-Unis","pt-BR":"Estados Unidos","zh-CN":"美国","es":"Estados Unidos","de":"USA","ja":"アメリカ合衆国"},"iso_code":"US"},"location":{"latitude":37.751,"accuracy_radius":100,"longitude":-97.822},"autonomous_system_organization":"Google LLC"}']
=== TEST 13: Test geo_lookup
--- http_config eval
"$::HttpConfig"
--- config
charset utf8;
location /t {
default_type text/plain;
charset utf-8;
content_by_lua_block {
local geo_lookup = require("geojs.utils").geo_lookup
local args = ngx.req.get_uri_args()
local ip = args.ip
local cjson = require("cjson")
ngx.print(cjson.encode(geo_lookup(ip)))
}
}
--- request eval
["GET /t?ip=8.8.8.8",
"GET /t?ip=2001:4860:4860::8888"]
--- no_error_log
[error]
--- response_body eval
['{"organization_name":"Google LLC","accuracy":1000,"asn":15169,"organization":"AS15169 Google LLC","longitude":"-97.822","country_code3":"USA","area_code":"0","ip":"8.8.8.8","country":"United States","continent_code":"NA","country_code":"US","latitude":"37.751"}','{"organization_name":"Google LLC","accuracy":100,"asn":15169,"organization":"AS15169 Google LLC","longitude":"-97.822","country_code3":"USA","area_code":"0","ip":"2001:4860:4860::8888","country":"United States","continent_code":"NA","country_code":"US","latitude":"37.751"}']
=== TEST 14: Test country_lookup
--- http_config eval
"$::HttpConfig"
--- config
charset utf8;
location /t {
default_type text/plain;
charset utf-8;
content_by_lua_block {
local country_lookup = require("geojs.utils").country_lookup
local args = ngx.req.get_uri_args()
local ip = args.ip
local cjson = require("cjson")
ngx.print(cjson.encode(country_lookup(ip)))
}
}
--- request eval
["GET /t?ip=8.8.8.8",
"GET /t?ip=2001:4860:4860::8888"]
--- no_error_log
[error]
--- response_body eval
['{"country":"US","country_3":"USA","ip":"8.8.8.8","name":"United States"}', '{"country":"US","country_3":"USA","ip":"2001:4860:4860::8888","name":"United States"}']

0 comments on commit 495843d

Please sign in to comment.