Mercurial > hg > nginx-tests
annotate fastcgi.t @ 114:44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
With test config nginx will fail to start as of 0.8.28 due to incorrect
conversion of regular expressions to lowercase. Patch was discussed on
mailing list and will be included in next release.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 Nov 2009 14:47:17 +0300 |
parents | 1c0ec30614c6 |
children | 8ac1faaddd2c |
rev | line source |
---|---|
30 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for fastcgi backend. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require FCGI; }; | |
31
baf9c51d166c
Tests: fix typo in fastcgi test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
30
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
30 | 26 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
27 my $t = Test::Nginx->new()->has('fastcgi')->plan(4) |
30 | 28 ->write_file_expand('nginx.conf', <<'EOF'); |
29 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
30 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
31 |
30 | 32 master_process off; |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
40 |
30 | 41 server { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
42 listen 127.0.0.1:8080; |
30 | 43 server_name localhost; |
44 | |
45 location / { | |
46 fastcgi_pass 127.0.0.1:8081; | |
47 } | |
48 } | |
49 } | |
50 | |
51 EOF | |
52 | |
53 $t->run_daemon(\&fastcgi_daemon); | |
54 $t->run(); | |
55 | |
56 ############################################################################### | |
57 | |
58 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); | |
59 like(http_get('/redir'), qr/302/, 'fastcgi redirect'); | |
60 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); | |
61 | |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
62 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD'); |
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
63 |
30 | 64 ############################################################################### |
65 | |
66 sub fastcgi_daemon { | |
44
daa295331acd
Tests: don't bind backend daemons to *, use 127.0.0.1 instead.
Maxim Dounin <mdounin@mdounin.ru>
parents:
41
diff
changeset
|
67 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
30 | 68 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
69 $socket); | |
70 | |
71 my $count; | |
72 while( $request->Accept() >= 0 ) { | |
40 | 73 $count++; |
74 print <<EOF; | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
75 Location: http://127.0.0.1:8080/redirect |
40 | 76 Content-Type: text/html |
77 | |
78 SEE-THIS | |
79 $count | |
80 EOF | |
30 | 81 } |
82 | |
83 FCGI::CloseSocket($socket); | |
84 } | |
85 | |
86 ############################################################################### |