comparison geo_binary.t @ 1044:1fe8d33f75ad

Tests: split out geo tests with binary base and skip by default. These tests require configuration with a large number of geo entries, which may cause long configuration parsing and enrage waitforfile().
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 30 Sep 2016 20:31:09 +0300
parents
children
comparison
equal deleted inserted replaced
1043:b82f54728e14 1044:1fe8d33f75ad
1 #!/usr/bin/perl
2
3 # (C) Andrey Zelenkov
4 # (C) Nginx, Inc.
5
6 # Tests for nginx geo module with binary base.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE};
26
27 my $t = Test::Nginx->new()->has(qw/http geo/);
28
29 $t->write_file_expand('nginx.conf', <<'EOF');
30
31 %%TEST_GLOBALS%%
32
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 geo $geo_base_create {
42 ranges;
43 include base.conf;
44 }
45
46 geo $geo_base_include {
47 ranges;
48 include base.conf;
49 }
50
51 server {
52 listen 127.0.0.1:8080;
53 server_name localhost;
54
55 location / {
56 add_header X-IP $remote_addr;
57 add_header X-GBc $geo_base_create;
58 add_header X-GBi $geo_base_include;
59 }
60 }
61 }
62
63 EOF
64
65 $t->write_file('1', '');
66 $t->write_file('base.conf', join('', map {
67 "127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
68 "-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
69 ($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
70
71 $t->run();
72
73 plan(skip_all => 'no 127.0.0.1 on host')
74 if http_get('/1') !~ /X-IP: 127.0.0.1/m;
75
76 $t->plan(2);
77
78 ###############################################################################
79
80 my $r = http_get('/1');
81 like($r, qr/^X-GBc: loopback/m, 'geo binary base create');
82 like($r, qr/^X-GBi: loopback/m, 'geo binary base include');
83
84 ###############################################################################