1 /* Copyright © 2012 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     geoip_db => GeoLiteCity-20111210.dat,
29     datacenters => [ us, ie, sg ]
30     auto_dc_coords => {
31      us = [ 38.9, -77 ]
32      ie = [ 53.3, -6.3 ]
33      sg = [ 1.3, 103.9 ]
34     }
35     map => {
36       default => [ us, ie, sg ],
37       EU => auto,
38     }
39    }
40 );
41 
42 gdmaps_t* gdmaps = NULL;
43 
main(int argc V_UNUSED,char * argv[]V_UNUSED)44 int main(int argc V_UNUSED, char* argv[] V_UNUSED) {
45     gdmaps_test_init(getenv("TEST_CFDIR"));
46     if(!gdmaps_test_db_exists("GeoLiteCity-20111210.dat")) {
47         plan_skip_all("Missing database");
48         exit(exit_status());
49     }
50     plan_tests(LOOKUP_CHECK_NTESTS * 3);
51     gdmaps = gdmaps_test_load(cfg);
52     //datacenters => [ us, ie, sg ]
53     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "137.138.144.168", "\2\1\3", 16); // Geneva
54     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "69.58.186.119", "\1\2\3", 16); // US East Coast
55     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "117.53.170.202", "\1\2\3", 8); // Australia
56     exit(exit_status());
57 }
58