Mercurial > hg > nginx-tests
annotate mp4_ssi.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 1923461981c9 |
children |
rev | line source |
---|---|
1056
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Test for mp4 module in subrequests. |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http mp4 ssi/)->has_daemon('ffprobe') |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->has_daemon('ffmpeg')->write_file_expand('nginx.conf', <<'EOF'); |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 server { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 listen 127.0.0.1:8080; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server_name localhost; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 location / { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 ssi on; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location /ssi { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 mp4; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 EOF |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 plan(skip_all => 'no lavfi') |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
1268
1923461981c9
Tests: prevent broken terminal after tc[gs]etattr ffmpeg race.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
55 system('ffmpeg -nostdin -loglevel quiet -y ' |
1056
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 . "${\($t->testdir())}/ssi.mp4") == 0 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 or die "Can't create mp4 file: $!"; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 $t->write_file('index.html', 'X<!--#include virtual="/ssi.mp4?end=1" -->X'); |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 $t->run()->plan(1); |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 ############################################################################### |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 (my $r = get('/')) =~ s/([^\x20-\x7e])/sprintf('\\x%02x', ord($1))/gmxe; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 unlike($r, qr/\\x0d(\\x0a)?0\\x0d(\\x0a)?\\x0d(\\x0a)?\w/, 'only final chunk'); |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 ############################################################################### |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 sub get { |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 my ($url, $extra) = @_; |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 return http(<<EOF); |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 GET $url HTTP/1.1 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 Host: localhost |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 Connection: close |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 EOF |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 } |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1e41a0de0772
Tests: various last_buf tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ############################################################################### |