annotate js_preload_object.t @ 1868:d570dbcad925

Tests: unbreak tests with IO::Socket:SSL lacking SSL_session_key.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 23 May 2023 13:21:27 +0400
parents c67b390cb9ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1789
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
1 #!/usr/bin/perl
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
2
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
3 # (C) Vadim Zhestikov
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
5
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
6 # Tests for http njs module, js_preload_object directive.
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
7
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
8 ###############################################################################
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
9
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
10 use warnings;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
11 use strict;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
12
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
13 use Test::More;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
14
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
16
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
17 use lib 'lib';
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
18 use Test::Nginx;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
19
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
20 ###############################################################################
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
21
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
22 select STDERR; $| = 1;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
24
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
27
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
29
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
30 daemon off;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
31
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
32 events {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
33 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
34
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
35 http {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
37
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
38 js_preload_object g1 from g.json;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
39 js_preload_object ga from ga.json;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
40
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
41 server {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
42 listen 127.0.0.1:8080;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
43 server_name localhost;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
44
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
45 js_import lib.js;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
46 js_preload_object lx from l.json;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
47
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
48 location /test {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
49 js_content lib.test;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
50 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
51
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
52 location /test_query {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
53 js_import lib1.js;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
54 js_content lib1.query;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
55 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
56
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
57 location /test_query_preloaded {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
58 js_import lib1.js;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
59 js_preload_object l.json;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
60 js_content lib1.query;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
61 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
62
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
63 location /test_var {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
64 js_set $test_var lib.test_var;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
65 return 200 $test_var;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
66 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
67
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
68 location /test_mutate {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
69 js_content lib.mutate;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
70 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
71
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
72 location /test_no_suffix {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
73 js_preload_object gg from no_suffix;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
74 js_content lib.suffix;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
75 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
76 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
77 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
78
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
79 EOF
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
80
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
81 $t->write_file('lib.js', <<EOF);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
82 function test(r) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
83 r.return(200, ga + ' ' + g1.c.prop[0].a + ' ' + lx);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
84 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
85
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
86 function test_var(r) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
87 return g1.b[2];
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
88 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
89
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
90 function mutate(r) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
91 var res = "OK";
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
92
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
93 try {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
94 switch (r.args.method) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
95 case 'set_obj':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
96 g1.c.prop[0].a = 5;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
97 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
98 case 'set_arr':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
99 g1.c.prop[0] = 5;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
100 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
101 case 'add_obj':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
102 g1.c.prop[0].xxx = 5;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
103 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
104 case 'add_arr':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
105 g1.c.prop[10] = 5;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
106 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
107 case 'del_obj':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
108 delete g1.c.prop[0].a;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
109 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
110 case 'del_arr':
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
111 delete g1.c.prop[0];
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
112 break;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
113 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
114
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
115 } catch (e) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
116 res = e.message;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
117 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
118
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
119 r.return(200, res);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
120 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
121
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
122 function suffix(r) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
123 r.return(200, gg);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
124 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
125
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
126 export default {test, test_var, mutate, suffix};
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
127
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
128 EOF
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
129
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
130 $t->write_file('lib1.js', <<EOF);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
131 function query(r) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
132 var res = 'ok';
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
133
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
134 try {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
135 res = r.args.path.split('.').reduce((a, v) => a[v], globalThis);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
136
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
137 } catch (e) {
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
138 res = e.message;
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
139 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
140
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
141 r.return(200, njs.dump(res));
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
142 }
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
143
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
144 export default {query};
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
145
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
146 EOF
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
147
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
148 $t->write_file('g.json',
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
149 '{"a":1, "b":[1,2,"element",4,5], "c":{"prop":[{"a":2}]}}');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
150 $t->write_file('ga.json', '"ga loaded"');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
151 $t->write_file('l.json', '"l loaded"');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
152 $t->write_file('no_suffix', '"no_suffix loaded"');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
153
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
154 $t->try_run('no js_preload_object available')->plan(12);
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
155
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
156 ###############################################################################
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
157
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
158 like(http_get('/test'), qr/ga loaded 2 l loaded/s, 'direct query');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
159 like(http_get('/test_query?path=l'), qr/undefined/s, 'unreferenced');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
160 like(http_get('/test_query_preloaded?path=l'), qr/l loaded/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
161 'reference preload');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
162 like(http_get('/test_query?path=g1.b.1'), qr/2/s, 'complex query');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
163 like(http_get('/test_var'), qr/element/s, 'var reference');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
164
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
165 like(http_get('/test_mutate?method=set_obj'), qr/Cannot assign to read-only/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
166 'preload_object props are const (object)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
167 like(http_get('/test_mutate?method=set_arr'), qr/Cannot assign to read-only/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
168 'preload_object props are const (array)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
169 like(http_get('/test_mutate?method=add_obj'), qr/Cannot add property "xxx"/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
170 'preload_object props are not extensible (object)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
171 like(http_get('/test_mutate?method=add_arr'), qr/Cannot add property "10"/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
172 'preload_object props are not extensible (array)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
173 like(http_get('/test_mutate?method=del_obj'), qr/Cannot delete property "a"/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
174 'preload_object props are not deletable (object)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
175 like(http_get('/test_mutate?method=del_arr'), qr/Cannot delete property "0"/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
176 'preload_object props are not deletable (array)');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
177
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
178 like(http_get('/test_no_suffix'), qr/no_suffix loaded/s,
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
179 'load without suffix');
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
180
c67b390cb9ef Tests: added js tests for js_preload_object directive.
Vadim Zhestikov <v.zhestikov@f5.com>
parents:
diff changeset
181 ###############################################################################