Mercurial > hg > nginx-tests
comparison addition.t @ 340:9920a522a2de
Tests: added tests for addition module.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 24 Sep 2013 18:13:58 +0400 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
339:9d0a2fa47ac6 | 340:9920a522a2de |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for addition module. | |
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 my $t = Test::Nginx->new()->has(qw/http rewrite addition/)->plan(9); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080; | |
41 server_name localhost; | |
42 | |
43 location /regular { | |
44 return 200 "body"; | |
45 } | |
46 | |
47 location /b.html { | |
48 add_before_body /add_before; | |
49 return 200 "body"; | |
50 } | |
51 | |
52 location /a.html { | |
53 add_after_body /add_after; | |
54 return 200 "body"; | |
55 } | |
56 | |
57 location /ba.html { | |
58 add_before_body /add_before; | |
59 add_after_body /add_after; | |
60 return 200 "body"; | |
61 } | |
62 | |
63 location /notype { | |
64 add_before_body /add_before; | |
65 add_after_body /add_after; | |
66 return 200 "body"; | |
67 } | |
68 | |
69 location /notype2 { | |
70 addition_types text/plain; | |
71 add_after_body /add_after; | |
72 return 200 "body"; | |
73 } | |
74 | |
75 location /notype.html { | |
76 types {} | |
77 add_before_body /add_before; | |
78 return 200 "body"; | |
79 } | |
80 | |
81 location /add_before { | |
82 return 200 "before"; | |
83 } | |
84 | |
85 location /add_after { | |
86 return 200 "after"; | |
87 } | |
88 | |
89 location /self.html { | |
90 add_after_body /self.html; | |
91 return 200 "self"; | |
92 } | |
93 | |
94 location /return202.html { | |
95 add_after_body /add_after; | |
96 return 202 "body"; | |
97 } | |
98 } | |
99 } | |
100 | |
101 EOF | |
102 | |
103 $t->run(); | |
104 | |
105 ############################################################################### | |
106 | |
107 like(http_get('/regular'), qr/^body$/ms, 'no addition'); | |
108 like(http_get('/b.html'), qr/^beforebody$/ms, 'add_before'); | |
109 like(http_get('/a.html'), qr/^bodyafter$/ms, 'add_after'); | |
110 like(http_get('/ba.html'), qr/^beforebodyafter$/ms, 'both'); | |
111 like(http_get('/notype'), qr/^body$/ms, 'no content type'); | |
112 like(http_get('/notype2'), qr/^bodyafter$/ms, 'addition_types'); | |
113 like(http_get('/notype.html'), qr/^body$/ms, 'empty content type'); | |
114 like(http_get('/self.html'), qr/^selfself$/ms, 'self'); | |
115 like(http_get('/return202.html'), qr/HTTP\/1.. 202.*^body$/ms, 'not 200'); | |
116 | |
117 ############################################################################### |