comparison ssi_stub.t @ 1990:85d88cd5091c default tip

Tests: SSI include stub tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 04 Jul 2024 17:42:55 +0300
parents
children
comparison
equal deleted inserted replaced
1989:bf027a972ccf 1990:85d88cd5091c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for nginx ssi module, stub output.
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 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(4)
25 ->write_file_expand('nginx.conf', <<'EOF');
26
27 %%TEST_GLOBALS%%
28
29 daemon off;
30
31 events {
32 }
33
34 http {
35 %%TEST_GLOBALS_HTTP%%
36
37 server {
38 listen 127.0.0.1:8080;
39 server_name localhost;
40
41 location / {
42 ssi on;
43 }
44
45 location = /empty {
46 # static
47 }
48
49 location = /error404 {
50 # static 404
51 }
52
53 location = /proxy404 {
54 proxy_pass http://127.0.0.1:8081;
55 proxy_intercept_errors on;
56 error_page 404 /error404;
57 }
58
59 location = /not_empty {
60 proxy_pass http://127.0.0.1:8081;
61 }
62 }
63
64 server {
65 listen 127.0.0.1:8081;
66 server_name localhost;
67 }
68 }
69
70 EOF
71
72 $t->write_file('empty.html',
73 '<!--#block name="fallback" -->fallback<!--#endblock -->' .
74 ':<!--#include virtual="/empty" stub="fallback" -->:');
75
76 $t->write_file('error.html',
77 '<!--#block name="fallback" -->fallback<!--#endblock -->' .
78 ':<!--#include virtual="/error404" stub="fallback" -->:');
79
80 $t->write_file('proxy_error.html',
81 '<!--#block name="fallback" -->fallback<!--#endblock -->' .
82 ':<!--#include virtual="/proxy404" stub="fallback" -->:');
83
84 $t->write_file('postponed.html',
85 '<!--#block name="fallback" -->fallback<!--#endblock -->' .
86 ':<!--#include virtual="/not_empty" -->' .
87 ':<!--#include virtual="/empty" stub="fallback" -->:');
88
89 $t->write_file('empty', '');
90 $t->write_file('not_empty', 'not empty');
91
92 $t->run();
93
94 ###############################################################################
95
96 like(http_get('/empty.html'), qr/:fallback:/, 'ssi stub empty');
97 like(http_get('/error.html'), qr/:fallback:/, 'ssi stub error');
98 like(http_get('/proxy_error.html'), qr/:fallback:/, 'ssi stub proxied error');
99
100 TODO: {
101 local $TODO = 'not yet' unless $t->has_version('1.27.2');
102
103 like(http_get('/postponed.html'), qr/:not empty:fallback:/s,
104 'ssi stub postponed');
105
106 }
107
108 ###############################################################################