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     datacenters => [ dc01, dc02 ],
29     nets => extn_subs.nets
30    }
31 );
32 
33 gdmaps_t* gdmaps = NULL;
34 
main(int argc V_UNUSED,char * argv[]V_UNUSED)35 int main(int argc V_UNUSED, char* argv[] V_UNUSED) {
36     gdmaps_test_init(getenv("TEST_CFDIR"));
37     plan_tests(LOOKUP_CHECK_NTESTS * 8);
38     gdmaps = gdmaps_test_load(cfg);
39     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "192.0.2.1", "\1", 1);
40     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "2600:3c02:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "\1", 6);
41     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "1234:000F::", "\2", 17);
42     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "1234:8000::1", "\1", 18);
43     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "1234:CFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "\2", 19);
44     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "1234:FFFF::1", "\1", 36);
45     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "1234:FFFF:1234:FFFF:FFFF:FFFF:FFFF:FFFF", "\2", 48);
46     gdmaps_test_lookup_check(gdmaps, "my_prod_map", "10.223.128.177", "\2\1", 15);
47     exit(exit_status());
48 }
49