annotate js_internal_redirect.t @ 1346:4d5d1e59f45e

Tests: TODO js_internal_redirect.t on njs < 0.2.2. On older njs versions, js runtime exception is thrown: "TypeError: cannot find property 'internalRedirect' of an external object".
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 14 Jun 2018 10:47:51 +0300
parents 9fbe84b7ddc6
children 106d9f806288
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
2
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
3 # (C) Dmitry Volyntsev
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
5
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
6 # Tests for http njs module, internalRedirect method.
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
7
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
8 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
9
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
10 use warnings;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
11 use strict;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
12
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
13 use Test::More;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
14
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
15 use Config;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
16
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
18
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
19 use lib 'lib';
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
21
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
22 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
23
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
26
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http/)
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
29
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
31
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
32 daemon off;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
33
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
34 events {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
35 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
36
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
37 http {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
38 %%TEST_GLOBALS_HTTP%%
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
39
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
40 js_include test.js;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
41
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
42 server {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
43 listen 127.0.0.1:8080;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
44 server_name localhost;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
45
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
46 location /njs {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
47 js_content test_njs;
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
48 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
49
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
50 location /test {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
51 js_content test_redirect;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
52 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
53
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
54 location /redirect {
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
55 internal;
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
56 return 200 redirect$arg_b;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
57 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
58
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
59 location @named {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
60 return 200 named;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
61 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
62 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
63 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
64
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
65 EOF
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
66
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
67 $t->write_file('test.js', <<EOF);
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
68 function test_njs(r) {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
69 r.return(200, njs.version);
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
70 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
71
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
72 function test_redirect(req) {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
73 if (req.variables.arg_dest.startsWith('named')) {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
74 req.internalRedirect('\@named');
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
75
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
76 } else {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
77 if (req.variables.arg_a) {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
78 req.internalRedirect('/redirect?b=' + req.variables.arg_a);
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
79
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
80 } else {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
81 req.internalRedirect('/redirect');
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
82 }
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
83 }
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
86 EOF
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
87
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
88 $t->try_run('no njs available')->plan(3);
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
91
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
92 TODO: {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
93 local $TODO = 'no njs internalRedirect'
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
94 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.2';
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
95
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96 like(http_get('/test'), qr/redirect/s, 'redirect');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97 like(http_get('/test?a=A'), qr/redirectA/s, 'redirect with args');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
98 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
99
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
100 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
101
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
102 ###############################################################################