1 /* Copyright © 2014 Brandon L Black <blblack@gmail.com>
2 *
3 * This file is part of gdnsd.
4 *
5 * gdnsd-plugin-geoip is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * gdnsd-plugin-geoip is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with gdnsd. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 // Unit test for gdmaps
21
22 #include <config.h>
23 #include "gdmaps_test.h"
24 #include <tap.h>
25
26 static const char cfg[] = QUOTE(
27 my_prod_map => {
28 geoip2_db => GeoLite2-City-20141008.mmdb,
29 datacenters => [ us, ie, sg ]
30 auto_dc_coords => {
31 ie = [ 53.3, -6.3 ]
32 sg = [ 1.3, 103.9 ]
33 us = [ 38.9, -77 ]
34 }
35 auto_dc_limit => 0 // unlimited
36 }
37 );
38
39 gdmaps_t* gdmaps = NULL;
40
main(int argc V_UNUSED,char * argv[]V_UNUSED)41 int main(int argc V_UNUSED, char* argv[] V_UNUSED) {
42 gdmaps_test_init(getenv("TEST_CFDIR"));
43 #ifndef HAVE_GEOIP2
44 plan_skip_all("No GeoIP2 support");
45 exit(exit_status());
46 #endif
47 if(!gdmaps_test_db_exists("GeoLite2-City-20141008.mmdb")) {
48 plan_skip_all("Missing database");
49 exit(exit_status());
50 }
51 plan_tests(LOOKUP_CHECK_NTESTS * 3);
52 gdmaps = gdmaps_test_load(cfg);
53 //datacenters => [ us, ie, sg ]
54 gdmaps_test_lookup_check(gdmaps, "my_prod_map", "137.138.144.168", "\2\1\3", 16); // Geneva
55 gdmaps_test_lookup_check(gdmaps, "my_prod_map", "69.58.186.119", "\1\2\3", 14); // US East Coast
56 gdmaps_test_lookup_check(gdmaps, "my_prod_map", "117.53.170.202", "\3\2\1", 23); // Australia
57 exit(exit_status());
58 }
59